zxc12538 2017-11-30 02:24 采纳率: 0%
浏览 3942

关于mybatis通用mapper的问题。

项目是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?

求大神解答,感激不仅!!!!~~~~

  • 写回答

4条回答

  • qq_41047780 2017-11-30 02:32
    关注

    'crBaseMapper' 是接口啊,不能实例化,单表crud自己写麻烦,用逆向工程就行啦

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog