Springboot mybatis常见配置问题解决

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Springboot mybatis常见配置问题解决

  2021-04-02 我要评论

这篇文章主要介绍了Springboot mybatis常见配置问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

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

打包的时候没有打包 mapper.xml 文件

<resource>
        <directory>src/main/resources</directory>
        <includes>
          <include>**/*</include>
        </includes>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>

没有扫描到 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文件

启动类添加mapper扫描

@MapperScan("com.example.demo.dao")
@SpringBootApplication
public class BlogApplication {
}

添加@Mapper注解

您可能感兴趣的文章:

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们