如果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/bgxml
3、pom.xml
<build><resources><resource><directory>src/main/resources</directory><filtering>true</filtering></resource><resource><directory>src/main/java</directory><includes><include>**/*.xml</include><include>**/*.json</include><include>**/*.ftl</include></includes></resource></resources>
</build>