做二手网站有哪些问题,网站建设设计流程图,济南网站建设报价,做网站最常用的软件是什么和mybatis一样的道理#xff01;#xff01;#xff01;#xff01;如果不指定这个配置#xff0c;通常要求 XML 映射文件和 Mapper 接口的包名和结构相同#xff01;#xff01;#xff01;#xff01;
如果没有配置 mapper-locations#xff0c;通常文件结构应遵循…和mybatis一样的道理如果不指定这个配置通常要求 XML 映射文件和 Mapper 接口的包名和结构相同
如果没有配置 mapper-locations通常文件结构应遵循如下约定
src
├── main
│ ├── java
│ │ └── com
│ │ └── example
│ │ └── mapper
│ │ └── UserMapper.java # Mapper接口
│ └── resources
│ └── com
│ └── example
│ └── mapper
│ └── UserMapper.xml # XML文件在 MyBatis-Plus 中mapper-locations 用于指定 Mapper XML 文件的路径MyBatis-Plus 会根据这个路径找到 XML 映射文件并自动加载到应用程序中。
1. mapper-locations 的作用
mapper-locations 指定了 MyBatis-Plus 映射文件*.xml 文件的加载路径。MyBatis-Plus 会根据这个路径扫描并加载对应的 Mapper XML 文件这些文件通常包含 SQL 语句如 select、insert、update、delete的定义以及 resultMap 等映射关系。
2. 配置项详解
在 application.yml 文件中可以通过如下配置来定义 mapper-locations
mybatis-plus:mapper-locations: classpath*:/mapper/**/*.xml在这里配置了一个路径模式
classpath*: 表示从类路径中搜索。/mapper/**/*.xml 表示在 mapper 目录下递归查找所有子目录中符合 *.xml 格式的文件。
例如如果你的项目结构如下
src
└── main└── resources└── mapper├── user│ └── UserMapper.xml└── product└── ProductMapper.xml配置了 classpath*:/mapper/**/*.xml 后MyBatis-Plus 会自动加载 mapper 文件夹中所有子文件夹user、product 等中的 *.xml 文件。 3. 路径写法说明
不同路径写法的含义如下
classpath:/mapper/*.xml表示只加载 resources/mapper 文件夹下的所有 .xml 文件不包括子文件夹。classpath*:/mapper/**/*.xml表示递归查找 resources/mapper 文件夹及其所有子文件夹下的 .xml 文件。