具有正则表达式的Spring URI模板模式 [英] Spring URI Template Patterns with Regular Expressions
本文介绍了具有正则表达式的Spring URI模板模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,有人知道如何匹配此URI" http://localhost: 8080/test/user/127.0.0.1:8002:8 "和@RequestMapping.
Hey someone know how can match this URI "http://localhost:8080/test/user/127.0.0.1:8002:8" with @RequestMapping.
我尝试编写以下代码:
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET,
headers = "Accept=application/xml")
public void test(@PathVariable("id") String id) {
System.out.println(id);
return null;
}
但是问题是当我打印id时,值是:127.0.0
.
也许有什么问题吗?
but the problem is when i print the id the value is: 127.0.0
.
Maybe something is wrong?
推荐答案
请参阅SpEL文档: http://static.springsource.org/spring/docs/3.0.5. RELEASE/reference/expressions.html
See the SpEL documentation: http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/expressions.html
您将要执行以下操作:
@RequestMapping(value = "/user/{id:.*}", method = RequestMethod.GET,headers="Accept=application/xml" )
public void test(@PathVariable("id") String id) {
这篇关于具有正则表达式的Spring URI模板模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文