ConfigurationProperties

 

 

<!--导入配置文件处理器,配置文件进行绑定就会有提示-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

 

 

 

@Component
@ConfigurationProperties(prefix = "mayikt")
public class MayiktUserEntity {
    private String addres;
    private String age;
    private String name;

    public String getAddres() {
        return addres;
    }

    public String getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    public void setAddres(String addres) {
        this.addres = addres;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "MayiktUserEntity{" +
                "addres='" + addres + '\'' +
                ", age='" + age + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}

 

 

 

在SpringBoot的配置文件中,我们可以使用SpringBoot提供的的一些随机数
${random.value}、${random.int}、${random.long}
${random.int(10)}、${random.int[1024,65536]}
-${app.name:默认值} 来制定找不到属性时的默认值

 

posted @ 2021-12-04 16:39  AngDH  阅读(50)  评论(0编辑  收藏  举报