springboot2:核心功能之配置问题及提示

一.配置文件

  • properties
  • yaml
    • 键:(空格)值
    • 缩进(空格,tab)表示层级关系,相同层级对齐
    • 字符串不需要加双引号
    • 字面量直接写
    • 对象需要缩进层级关系
    • 数组 -(空格)数据
    • 解析单引号双引号
      • 单引号中加入\n 会作为字符串输出
      • 双引号中加入\n 会作为换行输出
      • 双引号不转义(正常用),单引号转义(变普通)
  • 实例yaml
@ConfigurationProperties(prefix="person")
@Component
@Data
public class Person {
	
	private String userName;
	private Boolean boss;
	private Date birth;
	private Integer age;
	private Pet pet;
	private String[] interests;
	private List<String> animal;
	private Map<String, Object> score;
	private Set<Double> salarys;
	private Map<String, List<Pet>> allPets;
}

@Data
public class Pet {
	private String name;
	private Double weight;
}
  • properties表示以上对象
person.userName=xxx
  • yaml表示以上对象
#初始化对象
person:
  userName: zhangsan
  boss: false
  birth: 2019/12/12 20:12:33
  age: 18
  pet: 
    name: tomcat
    weight: 23.4
  #初始化数组[]
  interests: [篮球,游泳]
  #初始化列表 -(空格)
  animal: 
    - jerry
    - mario
  #初始化map
  score:
    english: 
      first: 30
      second: 40
      third: 50
    math: [131,140,148]
    #初始化map{}
    chinese: {first: 128,second: 136}
  salarys: [3999,4999.98,5999.99]
  allPets:
    sick:
      - {name: tom}
      - {name: jerry,weight: 47}
    health: [{name: mario,weight: 47}]
  • 加入注释处理器(写配置文件中配置类时无任何提示,难受)
    • 配置依赖
    • 打包过程中不打包其编写技巧(防止类太多)
		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency
				<configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值