问题描述:
- 在配置文件application.properties中写了
server.port=8081
server.servlet.context-path=/boy
name=张三
age=25
2.编写HelloController,获取配置文件中内容并展示
@RestController
public class HelloController {
@Value("${name}")
private String name;
@Value("${age}")
private String age;
@RequestMapping(value = "/hello",method = RequestMethod.GET)
public String say(){
return name+"同学"+"你的年纪"+age;
}
}
3.运行spring boot 主程序,打开http://localhost:8081/boy/hello
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTU4NjgwMi8yMDE5MDIvMTU4NjgwMi0yMDE5MDIyNzE2MDI0MjAxMC02NjY5NDE0NzYucG5n.png)
解决办法:
打开Settings>Editor>File Encodings ,
将Properties Files (*.properties) 下的Default encoding for properties files 设置为UTF-8 ,将Transparent native-to-ascii conversion 前的勾选上。
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTU4NjgwMi8yMDE5MDIvMTU4NjgwMi0yMDE5MDIyNzE2MDYyMzExOC0xMTQzMTA1MTEucG5n.png)
这是需要回application.properties重新编辑中文的部分,将乱码部分修改过来
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTU4NjgwMi8yMDE5MDIvMTU4NjgwMi0yMDE5MDIyNzE2MTkxOTMyMi04ODQzMTg3NC5wbmc=.png)
重新运行,打开,问题解决
![](https://www.codeprj.com/image/aHR0cHM6Ly9pbWcyMDE4LmNuYmxvZ3MuY29tL2Jsb2cvMTU4NjgwMi8yMDE5MDIvMTU4NjgwMi0yMDE5MDIyNzE1NTQxMDIwMS00OTQ0ODE1ODkucG5n.png)
|