问题描述:
- 在配置文件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
解决办法:
打开Settings>Editor>File Encodings ,
将Properties Files (*.properties) 下的Default encoding for properties files 设置为UTF-8 ,将Transparent native-to-ascii conversion 前的勾选上。
这是需要回application.properties重新编辑中文的部分,将乱码部分修改过来
重新运行,打开,问题解决
|