Просмотр исходного кода

使用抽象类+泛型实现通用service

shuzheng 9 лет назад
Родитель
Сommit
a841cc4cbe

+ 2 - 2
zheng-common/src/main/java/com/zheng/common/base/BaseService.java

@@ -8,7 +8,7 @@ import java.util.List;
  * BaseService接口
  * Created by ZhangShuzheng on 2017/01/07.
  */
-public interface BaseService<Mapper, Record, Example> {
+public interface BaseService<Record, Example> {
 
 	int countByExample(Example example);
 
@@ -40,6 +40,6 @@ public interface BaseService<Mapper, Record, Example> {
 
 	int deleteByPrimaryKeys(String ids);
 
-	void initMapper(Mapper mapper);
+	void initMapper(Class clazz);
 
 }

+ 5 - 3
zheng-common/src/main/java/com/zheng/common/base/BaseServiceImpl.java

@@ -1,8 +1,10 @@
 package com.zheng.common.base;
 
+import com.zheng.common.util.SpringContextUtil;
 import org.apache.commons.lang.StringUtils;
 import org.apache.ibatis.annotations.Param;
 
+import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.List;
 
@@ -10,7 +12,7 @@ import java.util.List;
  * 实现BaseService抽象类
  * Created by ZhangShuzheng on 2017/01/07.
  */
-public abstract class BaseServiceImpl<Mapper, Record, Example> implements BaseService<Mapper, Record, Example> {
+public abstract class BaseServiceImpl<Mapper, Record, Example> implements BaseService<Record, Example> {
 
 	public Mapper mapper;
 
@@ -206,8 +208,8 @@ public abstract class BaseServiceImpl<Mapper, Record, Example> implements BaseSe
 	}
 
 	@Override
-	public void initMapper(Mapper mapper) {
-		this.mapper = mapper;
+	public void initMapper(Class clazz) {
+		this.mapper = (Mapper) SpringContextUtil.getBean(clazz);
 	}
 
 }

+ 0 - 44
zheng-upms/zheng-upms-rpc-api/src/main/java/com/zheng/upms/rpc/api/BaseService.java

@@ -1,44 +0,0 @@
-package com.zheng.upms.rpc.api;
-
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-
-/**
- * baseService接口
- * @author shuzheng
- * @date 2016年7月7日 上午9:58:23
- */
-public interface BaseService<Record, Example> {
-
-	int countByExample(Example example);
-
-	int deleteByExample(Example example);
-
-	int deleteByPrimaryKey(Integer id);
-
-	int insert(Record record);
-
-	int insertSelective(Record record);
-
-	List<Record> selectByExampleWithBLOBs(Example example);
-
-	List<Record> selectByExample(Example example);
-
-	Record selectByPrimaryKey(Integer id);
-
-	int updateByExampleSelective(@Param("record") Record record, @Param("example") Example example);
-
-	int updateByExampleWithBLOBs(@Param("record") Record record, @Param("example") Example example);
-
-	int updateByExample(@Param("record") Record record, @Param("example") Example example);
-
-	int updateByPrimaryKeySelective(Record record);
-
-	int updateByPrimaryKeyWithBLOBs(Record record);
-
-	int updateByPrimaryKey(Record record);
-
-	int deleteByPrimaryKeys(String ids);
-
-}