本文主要是介绍如果xml在mapper目录下,如何扫描到xml,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
如果xml在mapper目录下,如何扫描到xml
项目结构
src├── main│ ├── java│ │ └── com│ │ └── bg│ │ ├── Application.java│ │ ├── domain│ │ │ └── User.java│ │ ├── mapper│ │ │ └── UserMapper.java│ │ │ └── xml│ │ │ └── UserMapper.xml│ │ └── service│ │ └── UserService.java│ └── resources│ ├── application.properties└── test└── java
1、启动类:
package com.bg;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
@MapperScan("com.bg.**.mapper")
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}
}
2、application.properties
# 数据源配置
spring.datasource.url=jdbc:mysql://localhost:3306/yourdatabase?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=yourusername
spring.datasource.password=yourpassword
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver# MyBatis 配置
mybatis.mapper-locations=classpath*:com/bg/**/xml/*Mapper.xml
3、pom.xml
<build><resources><!-- 配置资源目录 --><resource><!-- 指定资源文件的目录 --><directory>src/main/resources</directory><!-- 是否启用过滤 --><filtering>true</filtering></resource><!-- 配置Java目录中的资源文件 --><resource><!-- 指定资源文件的目录 --><directory>src/main/java</directory><!-- 包含的文件类型 --><includes><include>**/*.xml</include><include>**/*.json</include><include>**/*.ftl</include></includes></resource></resources>
</build>
这篇关于如果xml在mapper目录下,如何扫描到xml的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!