I. Introduction
Using SpringBoot
integration Mybatis
time of persistence framework for the Mybatis
interface class is generated *Mapper
, the interface classes *Mapper
, which acts as the Dao
role of the layer, and therefore a need to be labeled Bean
is injected into the Spring
container, to Spring
be managed. There are two ways to inject into Spring container management. For example, I have one ProductMapper
and one OrderMapper
:
- Method 1: Add a @Mapper annotation to both ProductMapper and OrderMapper interface classes
- Method 2: Add a @MapperScan to the SpringBoot startup class to specify the ProductMapper and OrderMapper class paths to be scanned.
The following describes the functions and implementation methods of the two annotations, as well as their advantages and disadvantages.
Two, @Mapper annotation
Use:*Mapper
Annotate on a single interface class , the corresponding interface implementation class will be generated after compilation, and the Bean will be injected into the Spring container.
Location: marked on a corresponding interface class.
Disadvantages:*Mapper
@Mapper annotations need to be marked on each interface class , which is very cumbersome, and this is a repetitive and useless work.