配置MapperScannerConfigurer
来源:互联网 发布:淘宝店铺怎么下架商品 编辑:程序博客网 时间:2024/05/23 15:01
注:该bean负责调用SqlSession的getMapper方法,获得 符合Mapper映射器要求的对象。并且会将这些对象放到spring 容器里面(默认的id是首字母小写之后的接口名,比如Mapper 映射器名为EmpDAO,则默认的id是empDAO,也可以使用@Repository 来修改默认的id)。
注:如果只扫描特定的映射器,可以做如下两步。
step1.开发一个注解,比如@MyBatisRepository,并且,将 该注解添加到需要扫描的映射器上面。
注:如果只扫描特定的映射器,可以做如下两步。
step1.开发一个注解,比如@MyBatisRepository,并且,将 该注解添加到需要扫描的映射器上面。
step2.给MapperScannerConfigurer注入annotationClass属性值。
代码如下:
自己写一个注解:
package annotations;public @interface MyBatisRepository {}
<!-- 配置MapperScannerConfigurer --><!-- 获得符合Mapper映射器要求的对象(相当于调用SqlSession的getMapper()方法)。并且会将这些对象放到spring容器里面(默认的id是首字母小写之后的接口名比如Mapper映射器名为EmpDAO,则默认的id是empDAO,也可以使用@Repository来修改默认的id --><bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 扫描该包及其子包下的所有映射器 --> <property name="basePackage" value="dao"/> <!-- 只扫描特定的接口 --> <!-- 含有特定注解的接口 --> <property name="annotationClass" value="annotations.MyBatisRepository"/></bean>
在映射器前面加入特定的注解
package dao;import java.util.List;import annotations.MyBatisRepository;import entity.Dept;@MyBatisRepository//扫描特定注解的接口public interface DeptDAO {public void save(Dept dept);//插入一条数据public List<Dept> findAll();//查询所有记录public Dept findById(int id);//根据id查询一条记录public void modify(Dept dept);//修改一条记录 public void delete(int id);//删除一条记录}
阅读全文
0 0
- 配置MapperScannerConfigurer
- MyBatis MapperScannerConfigurer配置
- MyBatis MapperScannerConfigurer配置
- MyBatis MapperScannerConfigurer配置
- Mybatis MapperScannerConfigurer 配置
- 使用MapperScannerConfigurer简化MyBatis配置
- Mybatis MapperScannerConfigurer配置问题总结
- MapperScannerConfigurer
- MapperScannerConfigurer
- 通过MapperScannerConfigurer配置Mybatis的一点研究
- mybatis整合spring使用MapperScannerConfigurer配置问题
- MyBatis MapperScannerConfigurer配置——MyBatis学习笔记之八
- MyBatis MapperScannerConfigurer配置——MyBatis学习笔记之一
- spring property-placeholder MapperScannerConfigurer无法读取配置的解决
- 关于Spring整合mybatis时配置MapperScannerConfigurer的问题
- spring 整合mybatis配置 MapperScannerConfigurer,无法读配置文件错误
- mybatis-spring:MapperScannerConfigurer、MapperScannerConfigurer
- MapperScannerConfigurer分析
- L1-004. 计算摄氏温度
- MFC的CwinApp与CFrameWnd的关系(3)-小白理解MFC
- Spring Boot初探
- BZOJ2299: [HAOI2011]向量
- web开发遇到的兼容性问题
- 配置MapperScannerConfigurer
- 华夏天龙
- 一点看到的东西
- 二进制文件简单加密
- 【luogu1005】矩阵取数游戏(高精度+dp)
- 【首发】(并没有什么用的)博客乔迁
- AndroidIP拨号器
- MySql安装步骤
- 淘宝的架构