一、classpath常用的场景
#mybatis配置
mybatis:
#注意,在创建mapper文件时,一定要注意文件名为xxxmapper.xml还是只是xxxmapper
#如果文件名为xxxmapper,就算该文件的格式为xml文件,配置为下面这样也是错误的
# mapper-locations: classpath:/mapper/*.xml
#将会报绑定异常。所以最佳的mapper文件地址配置的路径最好为下面这样:
mapper-locations: classpath:/mapper/*
spring:
#thymeleaf配置
thymeleaf:
suffix: .html
prefix: classpath:/templates/
二、classpath到底是什么
classpath表示编译后的文件夹路径,一般是从classes文件夹出发,项目编译后,java、resources、webapp文件夹下的子文件夹都会放在classes文件夹下,而classes文件夹又会放在target文件夹下。
1.编译前源文件架构

2.编译后生成的文件架构

本文介绍了classpath在Mybatis和Spring配置中的使用,强调了正确配置mapper文件位置的重要性。同时,详细阐述了classpath的概念,指出它通常指向编译后的classes目录,并展示了编译前后项目文件结构的区别。通过理解classpath,可以更好地管理和组织项目资源。
7173

被折叠的 条评论
为什么被折叠?



