网址不明确,其中一个带有PathVariable [英] Ambiguous URLs, one with PathVariable
问题描述
我有Spring 3.2 Web应用程序,并且我的控制器具有以下请求映射:
I have Spring 3.2 web app and i have controller with following request mappings:
@RequestMapping(value = "/test/{param1}", method = RequestMethod.GET)
public String method1(@PathVariable(value = "param1") String param1, ..
@RequestMapping(value = "/test/login", method = RequestMethod.GET)
public String method2(//..
我可以确定是否有人请求url/test/login来调用method2?是否有哪个因素决定弹簧的处理方式?是否始终选择不带PathVariable的URL(如果存在)?我在Spring文档中找不到任何内容.
Can I be sure that if someone ask for url /test/login the method2 will be invoked? Are there any factors based on which spring decides how to handle it? Does it always choose URL without PathVariable if any exists? I can't find anything in Spring doc.
推荐答案
我可以确定如果有人要求输入/test/login
网址,那么method2将被调用吗?
是的.
Can i be sure that if someone ask for url /test/login
the method2 will be invoked?
Yes.
The mappings are resolved by specificity, the relevant piece of doc is available here
具有较少URI变量和通配符的模式是 考虑得更具体.例如
/hotels/{hotel}/*
具有1个URI 变量和1个通配符,并且被认为比/hotels/{hotel}/**
作为1个URI变量和2个通配符.
A pattern with a lower count of URI variables and wild cards is considered more specific. For example
/hotels/{hotel}/*
has 1 URI variable and 1 wild card and is considered more specific than/hotels/{hotel}/**
which as 1 URI variable and 2 wild cards.
如果两个模式具有相同的计数,则更长的模式是
考虑得更具体.例如,/foo/bar*
更长,
被认为比/foo/*
更具体.
If two patterns have the same count, the one that is longer is
considered more specific. For example /foo/bar*
is longer and
considered more specific than /foo/*
.
当两个样式的计数和长度相同时,
较少的通配符被认为更具体.例如
/hotels/{hotel}
比/hotels/*
更具体.
When two patterns have the same count and length, the pattern with
fewer wild cards is considered more specific. For example
/hotels/{hotel}
is more specific than /hotels/*
.
如果两个映射与请求匹配,则将应用更具体的内容.在这两个映射中,/test/login
更具体.
If the two mappings match a request, a more specific will apply. Out of the two mappings, /test/login
is more specific.
这篇关于网址不明确,其中一个带有PathVariable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!