当前位置: 首页> 财经> 金融 > 如果xml在mapper目录下,如何扫描到xml

如果xml在mapper目录下,如何扫描到xml

时间:2025/7/11 18:51:46来源:https://blog.csdn.net/qq_44739966/article/details/139789493 浏览次数:0次

如果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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: