properties文件是Java文件中比较常见的文件,将数据集中在文件,通过配置直接读取
此篇记录的只是一种配置方法,有多种配置方法,
可参考:https://hy90171.iteye.com/blog/1868006
https://www.cnblogs.com/yucongblog/p/7338896.html
1.在applicationContext中配置:
<context:property-placeholder location="classpath:properties/*.properties" />
<util:properties id="urlprop" location="classpath:properties/url.properties"/>
也可配置多个properties文件
读取方式:
jsp页面:
利用标签读取
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:eval expression="@urlprop['url']" var="url"/>
<img src="//${url}/不同的路径
后端取值:
@Value("#{urlprop.url}")
private String urlImgDomain;
但是定义的变量不可以用static定义,以上就是配置+注解方式配置
也有用$符号取值的,但是配置会有不同,需要以后慢慢积累更新