Path Patterns 和 Patterns with Placeholders

除了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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章