您的位置:首頁技術文章
文章詳情頁

Springboot 掃描mapper接口的2種操作

瀏覽:5日期:2023-03-27 10:20:09
方式一:

在所有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出現的問題,在此記錄一下。

Springboot 掃描mapper接口的2種操作

實在是自己粗心大意了。

Springboot 掃描mapper接口的2種操作

解決方法

4、修改application文件中的mapper配置的路徑就好!

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。

標簽: Spring
相關文章:
国产综合久久一区二区三区