我是springboot项目 使用的mybatisplus
时间: 2023-08-28 16:06:48 浏览: 110
如果你是在Spring Boot项目中使用Mybatis-Plus,那么可以使用Mybatis-Plus提供的@TableName注解和Spring的@Value注解来获取配置文件中的自定义属性值。具体步骤如下:
1. 在配置文件中定义一个自定义属性,例如:
```
myapp.tablename=mytablename
```
2. 在实体类上使用@TableName注解,并使用@Value注解获取自定义属性值,例如:
```
@TableName(value = "${myapp.tablename}")
public class MyEntity {
// ...
}
```
3. 在Spring Boot的启动类上添加@MapperScan注解,扫描Mybatis-Plus的Mapper接口,例如:
```
@SpringBootApplication
@MapperScan("com.example.mapper")
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
```
4. 在Mapper接口中使用Mybatis-Plus提供的BaseMapper接口,例如:
```
public interface MyEntityMapper extends BaseMapper<MyEntity> {
// ...
}
```
这样就可以在Mybatis-Plus的@TableName注解中使用Spring的@Value注解,并获取配置文件中的自定义属性值作为表名。
阅读全文
相关推荐

















