当前位置:网站首页>@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
@MapperScanbe based onorg.mybatis:mybatis-spring:2.0.6,@Mapperbe 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
@MapperScanbe 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
边栏推荐
- [报告] Microsoft :Application of deep learning methods in speech enhancement
- Use of fluent custom fonts and pictures
- MySQL lock
- No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
- ArcMap connecting ArcGIS Server
- OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
- Codeforces Round #783 (Div. 2) D题解
- ESP8266-入门第一篇
- MySQL syntax collation (4)
- RuntimeError: Providing a bool or integral fill value without setting the optional `dtype` or `out`
猜你喜欢

Zero base to build profit taking away CPS platform official account

Deep learning -- Summary of Feature Engineering

Pdf reference learning notes

山大网安靶场实验平台项目-个人记录(五)

为何PostgreSQL即将超越SQL Server?

Application of DCT transform

Why is PostgreSQL about to surpass SQL Server?

NiO related Basics

@MapperScan与@Mapper

Zero cost, zero foundation, build profitable film and television applet
随机推荐
Matlab 2019 installation of deep learning toolbox model for googlenet network
openlayers draw矩形
命令-sudo
Summary of several relationships of UML class diagram
考试系统进入试卷优化思路
Network protocol: SCTP flow control transmission protocol
什么是消息队列
ArcMap连接 arcgis server
点云数据集常用处理
The difference between underline and dot of golang import package
Audio signal processing and coding - 2.5.3 the discrete cosine transform
Executor、ExecutorService、Executors、ThreadPoolExecutor、Future、Runnable、Callable
Build intelligent garbage classification applet based on Zero
Deep learning -- Summary of Feature Engineering
ArcGIS JS API dojoconfig configuration
@MapperScan与@Mapper
arcgis js api dojoConfig配置
Kubernetes入门到精通-在 Kubernetes 上安装 OpenELB
openlayers 5.0 当地图容器大小改变时,重新加载地图
openlayers 5.0 两种居中方式