您的位置:首页 > 编程语言 > Java开发

Path Patterns 和 Patterns with Placeholders

2015-08-12 22:28 465 查看
除了URI templates,@RequestMapping 也支持Ant-style的路径模式,例如:/myPath/*.do
.

URI templates 

Ant-style 混合的支持,例如:/owners/*/pets/{petId}。

@RequestMapping也支持
类似于${…}占位符,取自本地properties配置文件,system
properties配置文件或者是environment variables。

这个在路径需要自定义的情况下非常有用,对于这个更多的信息,请参考PropertyPlaceholderConfigurer类的API.

下面给出一个例子:

Springmvc.xml配置文件:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="fileEncoding" value="utf-8" />
<property name="locations">
<list>
<value>classpath:url.properties</value>
</list>
</property>
</bean>
@Controller
public class TestController2 {

@RequestMapping(value="${testUrl}")
public String testUrl(){
return "test2";
}

}


url.properties配置文件:
testUrl=/testUrl
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息