SpringCloud 解决Consider defining a bean of type ‘*Mapper‘ in your configuration.

分手后的思念是犯贱 2024-03-31 08:29 176阅读 0赞

第一种,在Mapper接口上贴@Mapper

  1. @Repository
  2. @Mapper
  3. public interface CommodityMapper {
  4. /**
  5. * 查询所有商品信息
  6. * @return List<Commodity> 所有商品信息
  7. */
  8. List<Commodity> selectAll();
  9. }

第二种,启动类上贴@MapperScan(value = “com.xiami.springboot.sbootdemo.mapper”)注解,告诉Spring,Mapper接口的位置

  1. @SpringBootApplication
  2. @MapperScan(value = "com.xiami.springboot.sbootdemo.mapper")
  3. public class SbootdemoApplication {
  4. public static void main(String[] args) {
  5. SpringApplication.run(SbootdemoApplication.class, args);
  6. }
  7. }

第三种,使用依赖
pom.xml

  1. <dependency>
  2. <groupId>org.mybatis.spring.boot</groupId>
  3. <artifactId>mybatis-spring-boot-starter</artifactId>
  4. <version>2.0.1</version>
  5. </dependency>

配置文件

  1. mybatis.mapper-locations=classpath*:mapper/*Mapper.xml
  2. mybatis.type-aliases-package=com.example.mybatissimple.entity

发表评论

表情:
评论列表 (有 0 条评论,176人围观)

还没有评论,来说两句吧...

相关阅读