Springboot 掃描mapper接口的2種操作
在所有mapper接口使用@Mapper注解
@Mapper (將包中的所有接口都標注為DAO層接口)public interface UserMapper { UserInfo getUserInfo(@Param('userId') String userId);}方式二:
在springboot的啟動類使用@MapperScan注解
(作用:將指定包中的所有接口都標注為DAO層接口,相當于在每一個接口上寫@Mapper)
@SpringBootApplication@MapperScan(basePackages = 'com.xiami.springboot.sbootdemo.mapper')public class SbootdemoApplication { @Autowired private ApplicationArguments applicationArguments; public static void main(String[] args) { SpringApplication.run(SbootdemoApplication.class, args); } }
補充:spring boot掃描多個mapper文件夾
1、今天在做項目的時候報錯(Invalid bound statement (not found):
com.reportSystem.dao.ReprotSystemDao.findTotalDrawCount)
2、最后排查問題,總以為是contorller或者service層出的問題,仔細比較過后發現還是一樣的效果,怎么改都報錯。
3、最后發現是配置文件掃描mapper文件夾下的mapper出現的問題,在此記錄一下。
實在是自己粗心大意了。
4、修改application文件中的mapper配置的路徑就好!
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。
相關文章: