参考 : https://blog.youkuaiyun.com/thc1987/article/details/78789426
方法一
@Value("${com.zyd.title}")
private String title;
注 : 导包 import org.springframework.beans.factory.annotation.Value;
方法二
注入
@Autowired
private Environment env;
注 : 导包 import org.springframework.core.env.Environment;
使用
private String getProperty(String name) {
String value = null;
try {
value = env.getProperty(name);
if (CharacterCodingUtil.checkISO(value)){
value = new String(value.getBytes("ISO-8859-1"), "UTF-8");
}
} catch (Exception e) {
}
return value;
}
CharacterCodingUtil 工具类 : https://blog.youkuaiyun.com/Lxinccode/article/details/79414138
其他方法见参考链接。
END。