配置文件中设置的开票人 李四 在项目中引用乱码
方法1:此时value就是要取的值李四,/application.properties为配置文件的名字
try {
Properties properties=new Properties();
InputStream inputStream = this.getClass().getResourceAsStream("/application.properties");
BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream));
properties.load(bf);
String value = properties.getProperty("invoice.clerk");
} catch (IOException e) {
e.printStackTrace();
}
方法二:
在类中使用@Value
@Value("${invoice.clerk}")
private String clerk;
在配置文件中设置utf-8
spring.banner.charset=UTF-8
spring.messages.encoding=UTF-8
spring.http.encoding.charset=UTF-8
spring.http.encoding.force=true
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
别忘了将IDEA设置UTF-8字符集