application.yaml配置文件

map hash object 方式1: k:{k1:v1,k2:v2,k3:v3}

方式二 

K:

K1: V1

K2: V2

K3: V3

注意冒号后面一定要写空格,再写值

array list queue

方式二 方式1 k::[v1,v2,v3]

K:

- v1,

- v2

用在yaxml文件中,例子:

application.yaml

person:
  boss: true
  birth: 2020/10/10
  age: 18
  pet:
    name: pet1
    weight: 99.99
  inerests:
    -insert1
    -insert2
    -insert3
  animal: [animal1,animal2,animal3]
  score:
    first: 30
    second: 40
    third: 50
    first2: 30
    second2: 40
    third2: 50
  salarys:
    - 5000
    - 6000
    - 7000
  allpets:
    dead: [{name: name1dead,weight: 100},{name: namedead2,weight: 200}]
    live:
      - { name: 汤姆猫 }
      - { name: jerry,weight: 47 }
  user-name: mike

 pserson

package com.example.springdemo2.pojo;

import lombok.Data;
import lombok.ToString;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import java.util.*;
@ConfigurationProperties(prefix = "person")
@Component
@ToString
@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, Integer> score;
    private Set<Double> salarys;
    private Map<String, List<Pet>> allPets;

}

注意在yml中userName:和 user- name是一样的,         -可以让后面的字母大写。

可以安装一个插件

这个插件可以使我在写配置文件的属性名时有提示

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

因为这个包只有在写代码时才会用到,所以注意在导出包时不要把这个包也导出了,会增大包的大小,而且用不到这个包。

设置不导出的包 

   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
<!--                配置打包插件-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
<!--                            配置在打包时忽略这个类,他是作用于编码阶段,将他方进包中,一点用都没有,只会使包变大-->
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值