@Data
@AllArgsConstructor
@NoArgsConstructor
@Component //必加 放到spring容器中
@ConfigurationProperties(prefix = "user")
public class User {
private Integer id;
private String userName;
private Integer age;
private String address;
private String birthday;
}
<!--加这个依赖,@ConfigurationProperties注解和yml文件的配置属性进行绑定会有提示 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>

本文介绍了一个使用Spring Boot实现的简单用户类(User),该类通过@ConfigurationProperties注解与yml配置文件绑定,实现了配置项的自动填充。文章还提到了为了在IDE中获得属性绑定提示,需要引入spring-boot-configuration-processor依赖。

被折叠的 条评论
为什么被折叠?



