JAVA读取整个配置文件,装载到一个map
resources——config——prop——map
/*初始化加载aliPropertiesMap*/
public void init(Map<String, String> map) {
try {
//加载resource文件(也可以加载resources)
Resource resources = new PathMatchingResourcePatternResolver().getResource("classpath:config/alipay.properties");
PropertiesFactoryBean config = new PropertiesFactoryBean();
config.setLocation(resources);
config.afterPropertiesSet();
Properties prop = config.getObject();
//循环遍历所有得键值对并且存入集合
for (String key : prop.stringPropertyNames()) {
map.put(key, (String) prop.get(key));
}
System.out.println("加载完成");
} catch (Exception e) {
new Exception("配置文件加载失败");
}
}
一。控制器获取 再mmap.put传到前端
1.application.yml
area: 宁德市
diji: 县
2.控制器获取
@Value("${diji}")
private String diji;
二。JS/Html读取
1.配置文件
2.js/html获取
[[#{area}]]
th:text = #{area}
th:value = #{area}