如何将Springboot中扫描mapper接口的两种操作合并为一个长尾?

2026-04-19 18:401阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计347个文字,预计阅读时间需要2分钟。

如何将Springboot中扫描mapper接口的两种操作合并为一个长尾?

方式一:使用Mapper接口和@Mapper注解

javapublic interface UserMapper { UserInfo getUserInfo(@Param(userId) String userId);}

方式二:在Spring Boot启动类中使用

java@SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}

方式一:

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

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

如何将Springboot中扫描mapper接口的两种操作合并为一个长尾?

标签:2种

本文共计347个文字,预计阅读时间需要2分钟。

如何将Springboot中扫描mapper接口的两种操作合并为一个长尾?

方式一:使用Mapper接口和@Mapper注解

javapublic interface UserMapper { UserInfo getUserInfo(@Param(userId) String userId);}

方式二:在Spring Boot启动类中使用

java@SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}

方式一:

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

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

如何将Springboot中扫描mapper接口的两种操作合并为一个长尾?

标签:2种