在Spring MVC中的视图中显示属性值

sat*_*shi 2 spring view spring-mvc

我正在努力做一些简单的工作.我真正需要做的就是在视图中写一个属性值,即:

<!DOCTYPE html>
<head>
    ...
    <base href="${properties.config.baseurl}" />
    ...
</head>
<body>
...
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我的Spring MVC配置(相关位):

<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="locations">
        <list><value>/WEB-INF/config.properties</value></list>
    </property>
</bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    <property name="exposedContextBeanNames">
        <list><value>properties</value></list>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)

/WEB-INF/config.properties文件:

config.baseurl = http://localhost:8080/
Run Code Online (Sandbox Code Playgroud)

视图根本不显示任何内容(即<base href="" />),任何人都可以向我解释原因吗?

谢谢.

ska*_*man 6

你需要使用

${properties['config.baseurl']}
Run Code Online (Sandbox Code Playgroud)

而不是

${properties.config.baseurl}
Run Code Online (Sandbox Code Playgroud)

否则它将尝试config.baseurl像bean路径一样导航,而不是像字符串文字那样导航.