温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Springboot mybatis常见配置问题解决

发布时间:2020-08-30 20:05:55 来源:脚本之家 阅读:175 作者:没有故事的安徒生 栏目:编程语言

这篇文章主要介绍了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注解

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI