springboot + mybatis 常见配置问题

Invalid bound statement (not found): com.example.blog.dao.DemoMapper.selectByExample"

  1. 打包的时候没有打包 mapper.xml 文件
<resources>
    <resource>
        <directory>src/main/resources</directory>
             <includes>
                <include>**/*</include>
             </includes>
           </resource>
           <resource>
         <directory>src/main/java</directory>
         <includes>
              <include>**/*.xml</include>
         </includes>
     </resource>
</resources>
  1. 没有扫描到 mapper.xml 文件
mybatis:
  # mapper.xml 文件路径
  mapper-locations: classpath:com/example/blog/dao/mapper/*.xml
  # mybatis的xml文件中需要写类的全限定名,可以配置自动扫描包路径给类配置别名
  type-aliases-package: com.example.blog.entity

Field demoMapper in com.example.demo.service.DemoServiceImpl required a bean of type 'com.example.demo.dao.DemoMapper' that could not be found.

原因:找不到dao层的mapper文件

  1. 启动类添加mapper扫描
@MapperScan("com.example.demo.dao")
@SpringBootApplication
public class BlogApplication {
}
  1. 添加@Mapper注解
posted @ 2019-11-22 11:57  没有故事的安徒生  阅读(297)  评论(0编辑  收藏  举报