OR博客
SpringBoot在yml中自定义自己的类来保存常量
苗锦洲
创建于:2020-08-25 13:11:32
0
29
182
0
平时存常量基本都是public static 数据类型,来试试SpringBoot的application.yml吧
# 用法 ## 1. application.yml配置文件 ``` xxx: ··· xxx: string: 字符串 # string: '字符串' special_string: "字\n符串" number: 6.6 list: [1,2,3] # list2: # - 1 # - 2 # - 3 # ... set: [1,2,3,1] # set2: # - one # - two # - one # ... map: {key1: value1, key2: value2,...} objectList: - object1_property1: xxx object1_property2: xxx ... - object2_property1: xxx object2_property2: xxx ... ``` ## 2.Java类 ``` @Component @ConfigurationProperties(prefix = "xxx.···.xxx") public class xxx { private 数据类型 xxx; //... //getters, setters } ```
评论
楼主暂时不想被别人评论哦~