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

This commit is contained in:
shuzheng 2017-01-06 23:26:02 +08:00
parent 8ad58a84d0
commit a841cc4cbe
3 changed files with 7 additions and 49 deletions

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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);
}