<> Write in front

stay SpringBoot In the project of , integrate Mybatis Behind the persistence layer framework , about Mybatis Interface classes of, such as :UserMapper,SysMenuMapper, These interface classes
Mapper Used to access the persistence layer , stay JPA Middle refers to DAO layer . stay Service Layer needs to use @Autowired or @Resource Called after annotation injection
Mapper When the method in , These interfaces need to be injected into Spring In context . There are two ways to complete injection :
In each class *Mapper Add one to the interface of @Mapper annotation .
stay SpringBoot Add one to the startup class of @MapperScan And indicate the package path .

<> Use difference

@Mapper And @MapperScan Cannot be used at the same time , otherwise @Mapper Annotation does not work .

Method 1 : use @Mapper
Directly in each corresponding Mapper Class @Mapper.Mapper When there are many classes , It is troublesome to use this way . @Mapper public interface
IssueMapper { /** * Query questions * * @param issueId test questions ID * @return test questions */ public Issue
selectIssueById(Long issueId); }
Method 2 : Use scan annotation @MapperScan
Add annotations on the corresponding startup class of each module @MapperScan("com.hadoopx.**.mapper"). You need to specify the scope of the scanning package , Can scan 1
One or more packages , You can also scan sub packages , Wildcards are required * perhaps ** To specify .
①. Specify a single package :
@MapperScan("com.hadoopx.issue.mapper") @SpringCloudApplication public class
ServicexYqxApplication { public static void main(String[] args) {
SpringApplication.run(ServicexYqxApplication.class, args); System.out.println(
" Learning together service started successfully ..."); } }
②. Specify multiple packages :
@MapperScan({"com.hadoopx.issue.mapper","com.hadoopx.test.mapper",
"com.hadoopx.paper.mapper"}) @SpringCloudApplication public class
ServicexYqxApplication { public static void main(String[] args) {
SpringApplication.run(ServicexYqxApplication.class, args); System.out.println(
" Learning together service started successfully ..."); } }
Or use wildcards :
// One * Delegate can only scan any single package , Cannot scan recursively @MapperScan("com.hadoopx.*.mapper")
@SpringCloudApplication public class ServicexYqxApplication { public static void
main(String[] args) { SpringApplication.run(ServicexYqxApplication.class, args);
System.out.println(" Learning together service started successfully ..."); } } // Two ** Delegate can scan any package , Can scan recursively @MapperScan(
"com.hadoopx.**.mapper") @SpringCloudApplication public class
ServicexYqxApplication { public static void main(String[] args) {
SpringApplication.run(ServicexYqxApplication.class, args); System.out.println(
" Learning together service started successfully ..."); } }

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?