Laughing
Spring Boot yaml文件配置列表
05/07
本文最后更新于2024年03月18日,已超过55天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
我们在Spring Boot
的yaml
配置文件中,一般配置的都是一些文本(字符串)。那么我们在yaml
文件中如何配置列表或者数组呢。
场景
试想一下我们的场景:我们系统涉及到租户,数据库采用行级别的隔离,也就是说表里面有一个org_code
列,作为租户之间数据隔离的条件,类似于where org_code = 'xx'
。但是,我们不是所有的表都要进行,那么我们在过滤某些表不进行过滤时,首先肯定想到的就是在yaml
文件中配置需要过滤的表名。
敲代码
yaml设置
# 项目相关配置
leeframe:
# 过滤表名,不进行租户的过滤
filterTableList:
- sys_dict_type
- sys_dict_data
- sys_config
- sys_organization
- sys_job
- sys_user_role
配置映射
@Component
@ConfigurationProperties(prefix = "leeframe")
public class LeeFrameConfig {
/**
* 过滤表名,不进行租户的过滤
*/
private static List<String> filterTableList;
public static List<String> getFilterTableList() {
return filterTableList;
}
public void setFilterTableList(List<String> filterTableList) {
LeeFrameConfig.filterTableList = filterTableList;
}
}
使用
LeeFrameConfig.getFilterTableList()
版权属于:
香草物语
本文链接:
https://www.xiangcaowuyu.net/java/springboot-yaml-file-configuration-list.html(转载时请注明本文出处及文章链接)
作品采用:
顶替夺标地顶替顶替