瀏覽代碼

Merge branch 'dev'

jobob 8 年之前
父節點
當前提交
ee5477b908

+ 1 - 1
mybatis-plus/src/main/java/com/baomidou/framework/service/impl/ServiceImpl.java

@@ -179,7 +179,7 @@ public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable
     }
 
     public int selectCount(EntityWrapper<T> entityWrapper) {
-        return baseMapper.selectCountByEW(entityWrapper);
+        return baseMapper.selectCountByEw(entityWrapper);
     }
 
 	public List<T> selectList(EntityWrapper<T> entityWrapper) {

+ 18 - 17
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/AutoSqlInjector.java

@@ -15,12 +15,13 @@
  */
 package com.baomidou.mybatisplus.mapper;
 
-import com.baomidou.mybatisplus.MybatisConfiguration;
-import com.baomidou.mybatisplus.annotations.FieldStrategy;
-import com.baomidou.mybatisplus.annotations.IdType;
-import com.baomidou.mybatisplus.toolkit.TableFieldInfo;
-import com.baomidou.mybatisplus.toolkit.TableInfo;
-import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
 import org.apache.ibatis.builder.MapperBuilderAssistant;
 import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
 import org.apache.ibatis.executor.keygen.KeyGenerator;
@@ -33,12 +34,12 @@ import org.apache.ibatis.scripting.LanguageDriver;
 import org.apache.ibatis.scripting.defaults.RawSqlSource;
 import org.apache.ibatis.session.Configuration;
 
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.logging.Logger;
+import com.baomidou.mybatisplus.MybatisConfiguration;
+import com.baomidou.mybatisplus.annotations.FieldStrategy;
+import com.baomidou.mybatisplus.annotations.IdType;
+import com.baomidou.mybatisplus.toolkit.TableFieldInfo;
+import com.baomidou.mybatisplus.toolkit.TableInfo;
+import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
 
 /**
  * <p>
@@ -495,8 +496,7 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * @param table
 	 */
 	protected void injectSelectListSql(SqlMethod sqlMethod, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-		String where = getStringBuilder(table);
-		String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(table, true), table.getTableName(), where);
+		String sql = String.format(sqlMethod.getSql(), sqlSelectColumns(table, true), table.getTableName(), sqlWhereEntityWrapper(table));
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
 		this.addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, modelClass, table);
 	}
@@ -511,19 +511,20 @@ public class AutoSqlInjector implements ISqlInjector {
 	 * @param table
 	 */
 	protected void injectSelectCountByEWSql(SqlMethod sqlMethod, Class<?> mapperClass, Class<?> modelClass, TableInfo table) {
-		String where = getStringBuilder(table);
-		String sql = String.format(sqlMethod.getSql(), table.getTableName(), where);
+		String sql = String.format(sqlMethod.getSql(), table.getTableName(), sqlWhereEntityWrapper(table));
 		SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
 		this.addSelectMappedStatement(mapperClass, sqlMethod.getMethod(), sqlSource, Integer.class, null);
 	}
 
 	/**
+	 * <p>
 	 * EntityWrapper方式获取select where
+	 * </p>
 	 *
 	 * @param table
 	 * @return String
 	 */
-	private String getStringBuilder(TableInfo table) {
+	protected String sqlWhereEntityWrapper(TableInfo table) {
 		StringBuilder where = new StringBuilder("\n<if test=\"ew!=null\">");
 		where.append("\n<if test=\"ew.entity!=null\">\n<where>");
 		where.append("\n<if test=\"ew.entity.").append(table.getKeyProperty()).append("!=null\">\n");

+ 11 - 10
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java

@@ -221,6 +221,16 @@ public interface BaseMapper<T, PK extends Serializable> {
 	 */
 	int selectCount( @Param("ew" ) T entity);
 
+	/**
+	 * <p>
+	 * 根据 EntityWrapper 条件,查询总记录数
+	 * </p>
+	 * 
+	 * @param entityWrapper
+	 * 				实体对象
+	 * @return int
+	 */
+	int selectCountByEw(@Param("ew") EntityWrapper<T> entityWrapper);
 
 	/**
 	 * <p>
@@ -231,7 +241,7 @@ public interface BaseMapper<T, PK extends Serializable> {
 	 * @return List<T>
 	 */
 	List<T> selectList( @Param("ew" ) EntityWrapper<T> entityWrapper);
-	
+
 	/**
 	 * <p>
 	 * 根据 entity 条件,查询全部记录(并翻页)
@@ -244,13 +254,4 @@ public interface BaseMapper<T, PK extends Serializable> {
 	 */
 	List<T> selectPage( RowBounds rowBounds, @Param("ew" ) EntityWrapper<T> entityWrapper);
 
-	/**
-	 * <p>
-	 * 根据 EntityWrapper 条件,查询总记录数
-	 * </p>
-	 * @param entityWrapper
-	 * 				实体对象
-	 * @return int
-	 */
-	int selectCountByEW(@Param("ew") EntityWrapper<T> entityWrapper);
 }

+ 1 - 1
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/SqlMethod.java

@@ -59,7 +59,7 @@ public enum SqlMethod {
 	SELECT_BATCH("selectBatchIds", "根据ID集合,批量查询数据", "<script>SELECT %s FROM %s WHERE %s IN (%s)</script>"),
 	SELECT_ONE("selectOne", "查询满足条件一条数据", "<script>SELECT %s FROM %s %s</script>"),
 	SELECT_COUNT("selectCount", "查询满足条件总记录数", "<script>SELECT COUNT(1) FROM %s %s</script>"),
-	SELECT_COUNT_EW("selectCountByEW", "查询满足条件总记录数", "<script>SELECT COUNT(1) FROM %s %s</script>"),
+	SELECT_COUNT_EW("selectCountByEw", "查询满足条件总记录数", "<script>SELECT COUNT(1) FROM %s %s</script>"),
 	SELECT_LIST("selectList", "查询满足条件所有数据", "<script>SELECT %s FROM %s %s</script>"),
 	SELECT_PAGE("selectPage", "查询满足条件所有数据(并翻页)", "<script>SELECT %s FROM %s %s</script>");