项目是maven管理的,用的mybatis+spring,单表的CRUD都需要手写,感觉很麻烦。于是网上找了通用mapper的配置方法。
在POM.XML加入了
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>${mapper.version}</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
这两个包配置。
然后新建了一个基本业务接口
public interface BaseService<T>{
}
基本业务接口的实现类:
@Service
public abstract class BaseServiceImpl<T> implements BaseService<T> {
CrBaseMapper<T> crBaseMapper;
@Resource
CourseMapper courseMapper;
public int add(T entity, boolean insertSelective)
{
if (insertSelective) {
return this.crBaseMapper.insertSelective(entity);
}
return this.crBaseMapper.insert(entity);
}
public int delete(T entity)
{
return this.crBaseMapper.deleteByPrimaryKey(entity);
}
public int update(T entity, boolean updateSelective)
{
if (updateSelective) {
return this.crBaseMapper.updateByPrimaryKeySelective(entity);
}
return this.crBaseMapper.updateByPrimaryKey(entity);
}
public T get(Long pk)
{
return this.crBaseMapper.selectByPrimaryKey(pk);
}
public List<T> selectAll() {
return this.crBaseMapper.selectAll();
}
}
然后就是基本DAO接口:
@Repository
public abstract interface CrBaseMapper<T> extends Mapper<T> {
}
。
最后在applicationContext.xml也进行了如下的配置:
<bean class="tk.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.isea533.mybatis.mapper"/>
<property name="properties">
<value>
mappers=tk.mybatis.mapper.common.Mapper
</value>
</property>
</bean>
<context:component-scan base-package="com.insi.cream"/>
是哪里配置有问题吗,为什么启动时候还是提示
Error creating bean with name 'crBaseMapper' defined in file?
求大神解答,感激不仅!!!!~~~~