开发者学堂课程【SpringBoot快速掌握 - 核心技术:properties配置文件编码问题 】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/612/detail/9224
properties配置文件编码问题
一、具体内容
配置的值如下:
person :
age: 18
boss: false
birth: 2017/12/12
maps:(k1: v1,k2: 12)
lists:
- lisi
- zhaoliu
dog:
name:小狗
age: 2
last-name: zhangsan
Ctrl+/
更改后:
#server.port=8081
# idea,propertiesh配置文件utff-8
# 配置person的值
需要编码转换
person.last-name=张三
person.age=18
person.birth=2017/12/15
person.boss=false
person.maps.k1=v1
person.maps.k2=14
person.lists=a,b,c
person.dog.name=dog
person.dog.age=15
另一种方法:
@Component
@ConfigurationProperties(prefix = "person")
public class Person {
private String lastName;
private Integer age;
private Boolean boss;
private Date birth;
private Map maps;
private List lists;
private Dog dog;
运行:
@Override
public String toString() {
return "Person(" +
"lastName='" + lastName +'\''+
",age="+ age +
",boss=" + boss +
",birth=" + birth +
",maps=" + maps +
",1ists=" + lists +
",dog=" + dog +
'}';
}
public String getLastName() {
return lastName;
}