mybatis-plus global-config.mapper-locations
时间: 2023-12-19 20:27:32 浏览: 39
mybatis-plus的global-config.mapper-locations属性是用来指定Mapper映射文件的位置的。它的作用是告诉Mybatis-Plus在哪里查找Mapper映射文件。这个属性可以配置为一个路径或者一个资源地址。
如果配置为路径,可以使用绝对路径或者相对路径。绝对路径是指完整的文件路径,相对路径是指相对于项目根目录的路径。如果配置为资源地址,可以使用类路径下的资源地址,如"classpath:mapper/*.xml"。
相关问题
mybatis-plus 配置 Oracle
MyBatis-Plus 支持 Oracle 数据库,可以通过在 `application.properties` 或 `application.yml` 文件中配置相关属性来使用。下面是一个示例 `application.properties` 文件:
```properties
# 数据源配置
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:ORCL
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
# MyBatis-Plus 配置
mybatis-plus.mapper-locations=classpath*:mapper/*.xml
mybatis-plus.global-config.db-config.id-type=auto
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
```
在上面的配置中,我们指定了 Oracle 数据库的连接 URL、用户名、密码和驱动程序的类名。我们还指定了 MyBatis-Plus 的配置,包括映射文件的位置、主键生成策略、逻辑删除值和未删除值。
需要注意的是,如果你使用的是 `application.yml` 文件,那么配置内容应该如下所示:
```yaml
# 数据源配置
spring:
datasource:
url: jdbc:oracle:thin:@localhost:1521:ORCL
username: your_username
password: your_password
driver-class-name: oracle.jdbc.driver.OracleDriver
# MyBatis-Plus 配置
mybatis-plus:
mapper-locations: classpath*:mapper/*.xml
global-config:
db-config:
id-type: auto
logic-delete-value: '1'
logic-not-delete-value: '0'
```
无论你使用哪种方式,都应该把 Oracle 驱动程序和 MyBatis-Plus 添加到你的项目依赖中,例如:
```xml
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.3.2</version>
</dependency>
```
这样就完成了 MyBatis-Plus 对 Oracle 数据库的配置。
SpringBatch集成mybatis-plus
要在Spring Batch项目中集成Mybatis-Plus,需要进行以下步骤:
1. 添加Mybatis-Plus依赖:在pom.xml文件中添加Mybatis-Plus的依赖。
```xml
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
```
2. 配置数据源:在application.properties文件中配置数据源。
```properties
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
```
3. 配置Mybatis-Plus:在application.properties文件中配置Mybatis-Plus。
```properties
mybatis-plus.mapper-locations=classpath:/mapper/*.xml
mybatis-plus.global-config.id-type=auto
mybatis-plus.global-config.db-config.logic-delete-value=1
mybatis-plus.global-config.db-config.logic-not-delete-value=0
```
4. 创建Mapper接口:创建Mapper接口继承BaseMapper接口。
```java
@Mapper
public interface UserMapper extends BaseMapper<User> {
}
```
5. 创建实体类:创建实体类并添加注解。
```java
@Data
@TableName("user")
public class User implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
private String name;
private Integer age;
}
```
6. 在Spring Batch任务中使用Mapper:在Spring Batch任务中使用Mapper。
```java
@Autowired
private UserMapper userMapper;
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
List<User> userList = userMapper.selectList(null);
// do something with user list
return RepeatStatus.FINISHED;
}
```
这样,就可以在Spring Batch项目中集成Mybatis-Plus了。