One, prepare the entity class
// 组件注入到容器并指定前缀
@Component
@ConfigurationProperties(prefix = "person")
@Data
@ToString
public class Person {
private String username;
private Boolean boss;
private Date birth;
private Integer age;
private Pat pat;
private String[] intersts;
private List<String> animal;
private Map<String, Object> score;
private Set<Double> salary;
private Map<String, List<Pat>> allPats;
}
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class Pat {
private String name;
private Integer age;
private Double weight;
public Pat(String name, Integer age) {
this.name = name;
this.age = age;
}
}
Second, the configuration file yml
person:
username: zhangsan
boss: true
birth: 2019/11/1
age: 1
intersts:
- 篮球
- 足球
animal: [小黑,小白]
score:
eng: 10
cn: 20
# score: {eng: 10, cn: 30} 以上两种方式都可以
salary:
- 8888.8
- 999.99
pat:
name: 啸天犬
age: 100
weight: 33.9
allPats:
sick:
- {name: xiaobai, weight: 88.8}
- name: xiaoyu,
weight: 12.1
health:
- name: lol,
weight: 12.3
- name: kkkk,
weight: 43.3
Test controller
@GetMapping("/hello")
public Person hello() {
return person;
}
Configuration file-configuration tips for custom class binding
Add the following dependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.4.2</version>
<optional>true</optional>
</dependency>
Three, configure banner
jpg picture or txt text, the default name is: banner.jpg
You can modify the name and specify it in the configuration file
spring:
banner:
charset: utf-8
image:
location: niu.jpeg
Detailed lecture notes: https://www.yuque.com/atguigu/springboot/rg2p8g
Lei Fengyang 2021 version of SpringBoot2 zero-based entry springboot full set of full version (spring boot2)
Lei Fengyang 2021 version of SpringBoot2 zero-based entry springboot full set of full version (spring boot2)