在我的应用程序上下文中,我定义了属性文件:

<context:property-placeholder  location="classpath:application.properties" />

我想获得JSP页面该文件中定义的属性的值。有没有办法以方式做到这一点

${something.myProperty}?
有帮助吗?

解决方案

PropertyPlaceholderConfigurer 只能用弹簧配置(XML或注释)解析占位符。在春季应用中非常常见 Properties 豆。您可以从视图中访问它(假设您正在使用 InternalResourceViewResolver):

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

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/>
    <property name="exposedContextBeanNames">
        <list><value>properties</value></list>
    </property>
</bean>

然后,在您的JSP中,您可以使用 ${properties.myProperty} 或者 ${properties['my.property']}.

其他提示

春季3.1之后,您可以使用 <spring:eval /> 标记 spel 像这样:

<spring:eval expression="@applicationProps['application.version']" 
             var="applicationVersion"/>

与列表中的多个位置一起使用,这些位置可能不在上下文中所做的不存在:属性地位持有人bean:

<beans:bean id="appProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <beans:property name="ignoreResourceNotFound" value="true" />
    <beans:property name="locations">
        <beans:list>
            <beans:value>classpath:application.properties</beans:value>
            <beans:value>classpath:environment.properties</beans:value>
            <beans:value>classpath:environment-${env}.properties</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>

要在视图中使用递归财产占位持有人的扩展,您需要一个不同的解决方案,请查看此答案:

https://stackoverflow.com/a/10200249/770303

`<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" 
  id="messageSource"
  p:basenames="WEB-INF/i18n/site"
  p:fallbackToSystemLocale="false"/>`

现在这是你的 属性文件

`site.name=Cool Bananas`

和。这是你的 JSP

`<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
  <head>
    <title><spring:message code="site.name"/></title>
  </head>
  <body>
  </body>
</html>`

这将向您显示当前架构的表(您已登录):

select table_name from user_tables order by table_name;

这将向您显示模式的表,至少您拥有精选权利:

select owner, table_name from all_tables where owner='<owner>' order by owner, table_name;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top