关于spring:Mapper和Repository的区别

2次阅读

共计 345 个字符,预计需要花费 1 分钟才能阅读完成。

    1、应用 @mapper 后,不须要在 spring 配置中设置扫描地址,通过 mapper.xml 外面的 namespace 属性对应相干的 mapper 类,spring 将动静的生成 Bean 后注入到 ServiceImpl 中。

    2、@repository 则须要在 Spring 中配置扫描包地址,而后生成 dao 层的 bean,之后被注入到 ServiceImpl 中
@Repository 注解润饰哪个类,则表明这个类具备对对象进行 CRUD(增删改查)的性能,而且 @Repository 是 @Component 注解的一个派生品,所以被 @Repository 注解的类能够主动的被 @ComponentScan 通过门路扫描给找到。(这也在肯定水平上解释了,为什么被 @Repository 注解的类也能 @Autowired)

正文完
 0