From 02a15977abff1bba26416b7442fb3008a347a874 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Sun, 25 Aug 2019 03:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E5=90=88mybatis-plus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 +- src/main/java/com/lq/code/dao/BaseDao.java | 4 +- .../com/lq/code/dao/impl/BaseDaoImpl.java | 126 ------------------ .../lq/code/interceptor/PageInteceptor.java | 2 +- src/main/resources/spring-mybatis-config.xml | 13 +- 5 files changed, 18 insertions(+), 136 deletions(-) delete mode 100755 src/main/java/com/lq/code/dao/impl/BaseDaoImpl.java diff --git a/pom.xml b/pom.xml index 9a744f5..469eaa2 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.1.1.RELEASE - 3.2.6 + 3.4.6 1.7.12 1.2.17 @@ -200,23 +200,24 @@ - + org.mybatis mybatis-spring - 1.2.2 + 2.0.1 com.baomidou mybatis-plus - 3.1.1 + 3.1.2 diff --git a/src/main/java/com/lq/code/dao/BaseDao.java b/src/main/java/com/lq/code/dao/BaseDao.java index 8024955..06c9b99 100755 --- a/src/main/java/com/lq/code/dao/BaseDao.java +++ b/src/main/java/com/lq/code/dao/BaseDao.java @@ -1,13 +1,15 @@ package com.lq.code.dao; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; import java.util.List; /** + * @author qi * Created by qi on 2017/7/16. */ -public interface BaseDao { +public interface BaseDao extends BaseMapper { /** * 保存对象,返回id diff --git a/src/main/java/com/lq/code/dao/impl/BaseDaoImpl.java b/src/main/java/com/lq/code/dao/impl/BaseDaoImpl.java deleted file mode 100755 index b09d77d..0000000 --- a/src/main/java/com/lq/code/dao/impl/BaseDaoImpl.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.lq.code.dao.impl; - -import com.lq.code.dao.BaseDao; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.jdbc.core.namedparam.SqlParameterSource; - -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.List; - -/** - * Created by qi on 2017/11/22. - */ -public class BaseDaoImpl implements BaseDao { - - @Autowired(required = false) - private JdbcTemplate jdbcTemplate; - - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; - - private Class entityClass; - - public BaseDaoImpl() { - Type genType = getClass().getGenericSuperclass(); - Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); - entityClass = (Class) params[0]; - } - - public void setJdbcTemplate(JdbcTemplate jdbcTemplate){ - this.jdbcTemplate=jdbcTemplate; - } - - public void setNamedParameterJdbcTemplate(){ - namedParameterJdbcTemplate=new NamedParameterJdbcTemplate(jdbcTemplate.getDataSource()); - } - - - @Override - public Long save(T entity) { - if (namedParameterJdbcTemplate==null){ - setNamedParameterJdbcTemplate(); - } - - SqlParameterSource parameterSource=new BeanPropertySqlParameterSource(entity); - - - return null; - } - - @Override - public void update(T t) { - StringBuffer sql=new StringBuffer(); - Field[] fields1= entityClass.getFields(); - for (Field field:fields1){ - field.setAccessible(true); - System.out.println(field); - } - Field[] fields=entityClass.getDeclaredFields(); - for (Field field:fields){ - System.out.println(field); - } - } - - @Override - public T findOne(Long id) { - return null; - } - - @Override - public List findAll() { - return null; - } - - @Override - public void delete(Long id) { - - } - - @Override - public void batchSave(List entitylist) { - - } - - @Override - public void batchUpdate(List entitylist) { - - } - - @Override - public void batchDelete(List entitylist) { - - } - - private String makeSql(String sqlType){ - StringBuffer sql=new StringBuffer(); - Field[] fields=entityClass.getFields(); - for (Field field:fields){ - System.out.println(field); - } - return sql.toString(); - } - - //将类名转换为表面,开启驼峰命名 - public String openHump(String entityName){ - StringBuffer strBuffer=new StringBuffer(); - char[] charArray=entityName.toCharArray(); - for (int i=0;i--> + + + + + - + - - + +