软件编程
位置:首页>> 软件编程>> java编程>> Springboot 扫描mapper接口的2种操作

Springboot 扫描mapper接口的2种操作

作者:粉果布丁甜甜圈  发布时间:2022-08-04 03:28:54 

标签:Springboot,扫描,mapper

方式一:

在所有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配置的路径就好!

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。如有错误或未考虑完全的地方,望不吝赐教。

来源:https://blog.csdn.net/xiaoxiamiqianqian/article/details/91576273

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com