1. 加载java目录下xml

报告异常

AbstractHandlerExceptionResolver.java:194 |org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver |Resolved exception caused by handler execution: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.guli.edu.mapper.CourseMapper.getCoursePublishVoById

问题分析:

dao层编译后只有class文件,没有mapper.xml,因为maven工程在默认情况下src/main/java目录下的所有资源文件是不发布到target目录下的,

Maven进行编译时候,只会把java文件进行编译,其他类型文件不会进行加载。也会把resources里面配置文件进行加载,其他地方配置文件不会进行加载

解决方案:

pom中配置如下节点

1
2
3
4
5
6
7
8
9
10
11
12
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

重新打包项目会发现target目录下出现了xml文件夹

2、在Spring Boot配置文件中添加配置

1
2
3
4
5

#mybatisplus日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#配置mapper xml文件的路径
mybatis-plus.mapper-locations=classpath:com/guli/edu/mapper/xml/*.xml

mybatis打印日志

1
2
3
logging:
level:
com.zzxx.mappertest.mapper: debug

2. IDEA使用Maven识别webapp时

开启插件 servlet

添加Web模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<build>

<!-- 使用idea开发工具时,需要加上该resources配置,解决webapp/资源目录无效的问题 -->
<resources>
<resource>
<directory>src/main/webapp</directory>
<!-- 编译的时候把webapp文件放到resources下,必须要放在此目录下才能被访问到 -->
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>

</resources>
</build>