当前位置:网站首页>@Mapperscan and @ mapper
@Mapperscan and @ mapper
2022-04-23 19:26:00 【justry_ deng】
@MapperScan And @Mapper
The background that
We're writing mapper when , You only need to write the interface without implementing it , from Mybatis The framework provides the corresponding proxy implementation class for the interface (, And register the proxy implementation class into the container ). however Mybatis How do you know which interfaces need to be proxy implemented , It is through @MapperScan And @Mapper Notes to know .
@MapperScan And @Mapper The role of
send Mybatis Know which interfaces need to be provided with proxy implementation .
adopt @Mapper Give Way Mybatis Provide proxy implementation for interface
Statement : Different versions mybatis There may be differences in the generation mechanism of proxy classes , The following conclusion
@MapperScan
be based onorg.mybatis:mybatis-spring:2.0.6
,@Mapper
be based onorg.mybatis:mybatis:3.5.9
-
Use... On the target interface @Mapper Note to identify
-
Ensure that the source code of the interface must be under the current project
namely : The interface must be the source code interface of the current project , It cannot be in other dependent class libraries , No @Mapper Will not enter into force .
notes : One might think that using @ComponentScan Other dependent classes in the library mapper Import is OK . In fact, it can't be ,@ComponentScan What is being scanned @Component Wait for the annotation to mark the class and register it in Spring Containers , And Mybatis The recognition mechanism of scanning generation agent class is two concepts .
notes : If you need to Mybatis For other dependent class libraries mapper Interface also generates proxy classes , Then please use @MapperScan
adopt @MapperScan Give Way Mybatis Provide proxy implementation for interface
Statement : Different versions mybatis There may be differences in the generation mechanism of proxy classes , The following conclusion
@MapperScan
be based onorg.mybatis:mybatis-spring:2.0.6
,@Mapper be based onorg.mybatis:mybatis:3.5.9
-
You just need to specify the range you want .Mybatis The corresponding proxy implementation will be carried out for all interfaces under this scope (, And register the proxy implementation class into the container ).
notes : The scope can include the scope within the current project , You can also include the scope of the class library that the current project depends on .
notes :@MapperScan All interfaces within the specified scope , All interfaces , Whether it's mapper Interface 、 still service Interface 、 Or some other interface , As long as the interface is @MapperScan Within the specified range ,Mybatis Will implement the corresponding proxy for this interface (, And register the proxy implementation class into the container ). therefore In the use of @MapperScan when , It must be noted that the specified range cannot be too large . Avoid the following :
Related information
- This article has been included in 《 Programmer growth notes 》 , The author JustryDeng
版权声明
本文为[justry_ deng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231923567470.html
边栏推荐
- SQL常用的命令
- DevOps集成-Jenkins 服务的环境变量和构建工具 Tools
- Openlayers 5.0 two centering methods
- 音频编辑生成软件
- MySQL syntax collation (4)
- Tencent cloud GPU best practices - remote development training using jupyter pycharm
- goroutine
- Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
- @Analysis of conditional on Web Application
- White screen processing method of fulter startup page
猜你喜欢
随机推荐
The difference between underline and dot of golang import package
Strange problems in FrameLayout view hierarchy
Core concepts of rest
Grafana 分享带可变参数的链接
openlayers 5.0 离散聚合点
How to uninstall easyton
What is a message queue
JS to get the local IP address
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
All table queries and comment description queries of SQL Server
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Reflection on the performance of some OpenGL operations in the past
[transfer] summary of new features of js-es6 (one picture)
SSDB Foundation
Virtual machine performance monitoring and fault handling tools
Zero base to build profit taking away CPS platform official account
Intuitive understanding of the essence of two-dimensional rotation
Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
深度学习——特征工程小总结
First experience of using fluent canvas