請問一下我在springBoot2上使用yml去裝載bean並透過controller把資料印出來
網頁上顯示的中文卻是unicode格式這是為什麼呢?我需要怎麼更改才能顯示中文
Controller
@RestController
public class PersonController {
@Autowired
Person person;
@RequestMapping(value = "/person", method = RequestMethod.GET)
public String index(){
return person.toString() ;
}
}
Bean
@Component
@ConfigurationProperties(prefix = "person")
@Data
public class Person {
private String lastname;
private String firstname;
private String name;
private String age;
private String birth;
private List<Object> list;
private Map<String,Object> map;
private Pet pet;
private String str1;
private String str2;
}
yml
person:
last-name: 測
first-name: 測試
name: 測測試
age: 21
birth: 2000/01/12
boy: false
list:
- 1
- 2
- 3
- a
- b
- c
map: {k1: v1, k2: v2}
pet:
name: dog
age: 11
str1: "雙引號會轉譯\n哈哈"
str2: '單引號不轉譯\n引號內的數據原封不動的輸出'
最後網頁輸出的結果會是
Person(lastname=\u6E2C, firstname=\u6E2C\u8A66, name=\u6E2C\u6E2C\u8A66, age=21, birth=2000/01/12, list=[1, 2, 3, a, b, c], map={k1=v1, k2=v2}, pet=Pet(name=dog, age=11), str1=雙引號會轉譯 哈哈, str2=\u55AE\u5F15\u865F\u4E0D\u8F49\u8B6F\n\u5F15\u865F\u5167\u7684\u6578\u64DA\u539F\u5C01\u4E0D\u52D5\u7684\u8F38\u51FA)