@Mapper与@MapperScan注解

@Mapper

@Mapper = Mapper.xml文件

作用在dao(mapper)层上的一个注解,将接口生成一个动态代理类,有了这个注解就不用

再写Mapper.xml文件

如果缺少这个注解,运行项目就会报相应的错误

@Mapper与@MapperScan注解_第1张图片

Field userMapper in com.example.controller.LoginController required a bean of type 'com.example.mapper.UserMapper' that could not be found.

https://blog.csdn.net/m0_67930426/article/details/133817769?spm=1001.2014.3001.5501

@MapperScan 

在Dao层下多个接口文件存在的时候,我们给每个接口文件添加@Mapper注解就会显得非常麻烦

有时也会忘记添加@Mapper注解

所以在对于多个接口存在的情况,使用@MapperScan注解一步到位

只需在启动类中添加该注解

@Mapper与@MapperScan注解_第2张图片

@Mapper与@MapperScan注解_第3张图片 

所以是@MapperScan("com.example.mapper")

 

你可能感兴趣的:(SpringBoot,mybatis,java,spring)