Przeglądaj źródła

Merge remote-tracking branch 'origin/dev'

hubin 8 lat temu
rodzic
commit
efc8f934f9

+ 5 - 5
mybatis-plus/src/main/java/com/baomidou/framework/service/IService.java

@@ -29,7 +29,7 @@ import com.baomidou.mybatisplus.plugins.Page;
  * @author hubin
  * @Date 2016-04-20
  */
-public interface IService<T, I> {
+public interface IService<T, PK> {
 
 	/**
 	 * <p>
@@ -73,7 +73,7 @@ public interface IService<T, I> {
 	 *            主键ID
 	 * @return boolean
 	 */
-	boolean deleteById(I id);
+	boolean deleteById(PK id);
 
 	/**
 	 * <p>
@@ -106,7 +106,7 @@ public interface IService<T, I> {
 	 *            主键ID列表
 	 * @return boolean
 	 */
-	boolean deleteBatchIds(List<I> idList);
+	boolean deleteBatchIds(List<PK> idList);
 
 	/**
 	 * <p>
@@ -176,7 +176,7 @@ public interface IService<T, I> {
 	 *            主键ID
 	 * @return T
 	 */
-	T selectById(I id);
+	T selectById(PK id);
 
 	/**
 	 * <p>
@@ -187,7 +187,7 @@ public interface IService<T, I> {
 	 *            主键ID列表
 	 * @return List<T>
 	 */
-	List<T> selectBatchIds(List<I> idList);
+	List<T> selectBatchIds(List<PK> idList);
 
 	/**
 	 * <p>

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

@@ -15,6 +15,7 @@
  */
 package com.baomidou.framework.service.impl;
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 
@@ -27,13 +28,13 @@ import com.baomidou.mybatisplus.plugins.Page;
 
 /**
  * <p>
- * IService 实现类( 泛型:M 是 mapper 对象, T 是实体 , I 是主键泛型 )
+ * IService 实现类( 泛型:M 是 mapper 对象,T 是实体 , PK 是主键泛型 )
  * </p>
  *
  * @author hubin
  * @Date 2016-04-20
  */
-public class ServiceImpl<M extends BaseMapper<T, I>, T, I> implements IService<T, I> {
+public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable> implements IService<T, PK> {
 
     @Autowired
     protected M baseMapper;
@@ -60,7 +61,7 @@ public class ServiceImpl<M extends BaseMapper<T, I>, T, I> implements IService<T
         return retBool(baseMapper.insertBatch(entityList));
     }
 
-    public boolean deleteById(I id) {
+    public boolean deleteById(PK id) {
         return retBool(baseMapper.deleteById(id));
     }
 
@@ -72,7 +73,7 @@ public class ServiceImpl<M extends BaseMapper<T, I>, T, I> implements IService<T
         return retBool(baseMapper.deleteSelective(entity));
     }
 
-    public boolean deleteBatchIds(List<I> idList) {
+    public boolean deleteBatchIds(List<PK> idList) {
         return retBool(baseMapper.deleteBatchIds(idList));
     }
 
@@ -96,11 +97,11 @@ public class ServiceImpl<M extends BaseMapper<T, I>, T, I> implements IService<T
         return retBool(baseMapper.updateBatchById(entityList));
     }
 
-    public T selectById(I id) {
+    public T selectById(PK id) {
         return baseMapper.selectById(id);
     }
 
-    public List<T> selectBatchIds(List<I> idList) {
+    public List<T> selectBatchIds(List<PK> idList) {
         return baseMapper.selectBatchIds(idList);
     }
 

+ 6 - 5
mybatis-plus/src/main/java/com/baomidou/mybatisplus/mapper/BaseMapper.java

@@ -15,6 +15,7 @@
  */
 package com.baomidou.mybatisplus.mapper;
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
 
@@ -32,7 +33,7 @@ import org.apache.ibatis.session.RowBounds;
  * @author hubin
  * @Date 2016-01-23
  */
-public interface BaseMapper<T, I> {
+public interface BaseMapper<T, PK extends Serializable> {
 
 	/**
 	 * <p>
@@ -74,7 +75,7 @@ public interface BaseMapper<T, I> {
 	 * 			主键ID
 	 * @return int
 	 */
-	int deleteById( I id );
+	int deleteById( PK id );
 
 
 	/**
@@ -107,7 +108,7 @@ public interface BaseMapper<T, I> {
 	 * 				主键ID列表
 	 * @return int
 	 */
-	int deleteBatchIds( List<I> idList );
+	int deleteBatchIds( List<PK> idList );
 
 
 	/**
@@ -174,7 +175,7 @@ public interface BaseMapper<T, I> {
 	 * 			主键ID
 	 * @return T
 	 */
-	T selectById( I id );
+	T selectById( PK id );
 
 
 	/**
@@ -185,7 +186,7 @@ public interface BaseMapper<T, I> {
 	 * 				主键ID列表
 	 * @return List<T>
 	 */
-	List<T> selectBatchIds( List<I> idList );
+	List<T> selectBatchIds( List<PK> idList );
 	
 	
 	/**

+ 7 - 0
mybatis-plus/src/main/java/com/baomidou/mybatisplus/plugins/PerformanceInterceptor.java

@@ -129,6 +129,13 @@ public class PerformanceInterceptor implements Interceptor {
 		} else {
 			result = "null";
 		}
+
+		/* 特殊处理 $ 符内容 */
+		if (null != result && result.contains("$")) {
+			return sql.replaceFirst("\\?", "[?]").replace("[?]", result);
+		}
+
+		/* 填充占位符 */
 		return sql.replaceFirst("\\?", result);
 	}
 

+ 5 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/UserMapperTest.java

@@ -35,6 +35,11 @@ import com.baomidou.mybatisplus.toolkit.IdWorker;
  * <p>
  * MybatisPlus 测试类
  * </p>
+ * <p>
+ * 自动提交了事务问题:<br>
+ * http://www.mybatis.org/spring/transactions.html#programmatic<br>
+ * https://github.com/mybatis/spring/issues/39<br>
+ * </p>
  *
  * @author hubin
  * @Date 2016-01-23