欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Springboot 掃描mapper接口的2種操作

 更新時間:2021年01月28日 17:32:29   作者:粉果布丁甜甜圈  
這篇文章主要介紹了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層出的問題,仔細比較過后發(fā)現(xiàn)還是一樣的效果,怎么改都報錯。

3、最后發(fā)現(xiàn)是配置文件掃描mapper文件夾下的mapper出現(xiàn)的問題,在此記錄一下。

實在是自己粗心大意了。

解決方法

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

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。如有錯誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評論