SpringCloud 解决Consider defining a bean of type ‘*Mapper‘ in your configuration.
第一种,在Mapper接口上贴@Mapper
@Repository
@Mapper
public interface CommodityMapper {
/**
* 查询所有商品信息
* @return List<Commodity> 所有商品信息
*/
List<Commodity> selectAll();
}
第二种,启动类上贴@MapperScan(value = “com.xiami.springboot.sbootdemo.mapper”)注解,告诉Spring,Mapper接口的位置
@SpringBootApplication
@MapperScan(value = "com.xiami.springboot.sbootdemo.mapper")
public class SbootdemoApplication {
public static void main(String[] args) {
SpringApplication.run(SbootdemoApplication.class, args);
}
}
第三种,使用依赖
pom.xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
配置文件
mybatis.mapper-locations=classpath*:mapper/*Mapper.xml
mybatis.type-aliases-package=com.example.mybatissimple.entity
还没有评论,来说两句吧...