Mybatis配置问题报错或查不到数据

1、Mybatis配置问题
1、首先查看自己的MyBatis扫描路径是否正确
2、再看下自己的映射实体包路径是否正确
3、将SQL语句打印出来,查看SQL是否出错
4、是否开启驼峰映射(Mybatis默认驼峰式关闭状态)

以下附上Mybatis简单配置
mybatis:
  #mapper.xml所在文件
  mapper-locations: classpath*:com/mmh/example/mapper/**/*.xml
  #映射类所在路径
  type-aliases-package: com.mmh.example.entity
  configuration:
    #执行打印SQL日志
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
    #开启驼峰式映射
    map-underscore-to-camel-case: true

2、MyBatis报错问题 找不到com.example.mapper.XXX.xml
1、首先查看自己的target对应文件下是否生成xml文件
2、查看自己的Mapper类是否和自己的xml文件名对应
3、按着Ctrl键鼠标是否可以单击进对应的Mapper类或方法
4、以上全部满足,则重新构建下项目或重启IDEA

以下附上target下不存在xml文件的配置
本配置存在于pom.xml 文件中 build 层级下

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

猜你喜欢

转载自blog.csdn.net/weixin_44821114/article/details/132141312