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

时间:2023-01-06 07:56:17


pom.xml
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.1</version>
</dependency>
1.在Mapper接口上贴@Mapper@Repository
@Mapper
public interface CommodityMapper {
/**
* 查询所有商品信息
* @return List<Commodity> 所有商品信息
*/
List<Commodity> selectAll();
}
2.启动类上贴@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);
}

}