yaml grammar and assignment

yaml grammar and assignment

springboot use a global configuration file, the configuration file name is fixed

  • application.properties

    • key=value
  • applicaton.yaml

    • key: value (Note: The space after)

    • server:
        port: 8081

At the same time it can be used to store objects yaml array

#对象
boy:
  name: 野原新之助
  age: 5
#行内写法
girl: {name: 野原向日葵,age: 1}

#数组
fruits:
  - apple
  - banana
  - peach
#行内写法
pets: [cat,dog,pig]

By yaml assignment

person:
  name: 野原新之助
  boy: true
  age: 5
  birthday: 1982/5/5
  maps: {k1: v1,k2: v2}
  list:
    - ${random.uuid}-随机生成uuid
    - ${random.int}-随机数
    - ${person.girlfriend:non}-如果存在girlfriend则为girlfriend的值,不存在则为non
  dog:
    name: 小白
    age: 3

In the original entity class plus

@ConfigurationProperties(prefix = "person")

Test category

@Autowired
private Person person;

Prompted the

Workaround: Add dependence

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

JSR303 efficacy

In the original entity class plus

@Validated

Guess you like

Origin www.cnblogs.com/pinked/p/12334394.html