@configurationproperties annotation assigns values to properties

first step

Import the annotated jar package

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

Second step

Use annotations in entity classes

@ToString
@Data
@AllArgsConstructor
@NoArgsConstructor
@Configuration	//prefix起名字 在yml文件里绑定
@ConfigurationProperties(prefix = "haidong")//名字自定义
public class dog {
    
    
    private Integer id;
    private String name;
    private String pwd;
    private Integer age;
}

third step

Write the value to the attribute in the yml file

haidong:
  id: 1
  name: mingzi
  pwd: abc
  age: 39

the fourth step

test

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45967375/article/details/115195956