TypechoJoeTheme

香草物语

统计
登录
用户名
密码
/
注册
用户名
邮箱
输入密码
确认密码

Spring Boot yaml文件配置列表

Laughing博主
2021-05-07
/
0 评论
/
1,155 阅读
/
193 个字
/
百度已收录
05/07
本文最后更新于2024年03月18日,已超过55天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

我们在Spring Bootyaml配置文件中,一般配置的都是一些文本(字符串)。那么我们在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()
Spring Bootspring
朗读
赞(1)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

香草物语

本文链接:

https://www.xiangcaowuyu.net/java/springboot-yaml-file-configuration-list.html(转载时请注明本文出处及文章链接)

评论 (0)
  1. sdfs 闲逛
    MacOS · Google Chrome

    顶替夺标地顶替顶替

    2019-10-21 回复

互动读者

  • Laughing闲逛

    评论 1 次 | 文章 541 篇

  • 芽儿哟闲逛

    评论 1 次 | 文章 0 篇

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月