In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the use of @ MapperScan annotations under mybatis-spring". In the daily operation, I believe many people have doubts about the use of @ MapperScan annotations under mybatis-spring. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about the use of @ MapperScan annotations under mybatis-spring! Next, please follow the editor to study!
Catalogue
Mybatis-spring:@MapperScan comments
@ MapperScan source code
MapperScannerRegistrar.class
Demo: springboot+mybatis
Engineering code
Mybatis-spring:@MapperScan comments
In the example of demo: springboot+mybatis, the dao layer interface uses the annotation @ MapperScan: specify all interface classes under the path of the package where com.xuxd.demo.dao.UserDao is scanned.
This article analyzes what the @ MapperScan annotation does.
@ MapperScan source code @ Retention (RetentionPolicy.RUNTIME) @ Target (ElementType.TYPE) @ Documented@Import (MapperScannerRegistrar.class) public @ interface MapperScan {/ * default attribute (= = basePackages), alias of basePackages * / String [] value () default {}; / * which interfaces under the packet path are scanned and registered (the interface has at least one method). The specific implementation class (non-interface) ignores * / String [] basePackages () default {} / * all interfaces under the package of the specified class are scanned and registered (the interface has at least one method). The specific implementation class (non-interface) ignores * / Class [] basePackageClasses () default {} / * the interfaces that meet the criteria must first register their relevant bean definitions in the spring container. When you register the bean definition *, you need to define the bean name, which is a policy component that generates the bean name from the subscriber. I think * / Class markerInterface () default Class.class is rarely used. / * this may be used for multiple data sources. The * / String sqlSessionTemplateRef () default "" is explained separately later; / * this may be used for multiple data sources, and the * / String sqlSessionFactoryRef () default "" is explained separately later. " / * this may be used for multiple data sources. This is explained separately later * / Class markerInterface = annoAttrs.getClass ("markerInterface"); if (! Class.class.equals (markerInterface)) {scanner.setMarkerInterface (markerInterface) } Class id,age,username select * from user insert into user () values (# {id}, # {age}, # {username}) DELETE from USER where id = 10
Application.properties
# data source configmysql.driver=com.mysql.jdbc.Drivermysql.username=rootmysql.passwd=123456mysql.url=jdbc:mysql://localhost:3306/testdb?useSSL=false
Pom.xml
4.0.0 com.xuxd spring-mybatis.demo 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent 1.5.6.RELEASE org.springframework.boot spring-boot-starter-web org.springframework spring-jdbc 4.3.1. RELEASE org.mybatis mybatis 3.3.1 org.mybatis mybatis-spring 1.2.5 mysql mysql-connector-java 5.1.43
The debug source code of this project will be used later.
At this point, the study on "how to use @ MapperScan annotations under mybatis-spring" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.