用于GET url参数的SpringMVC RequestMapping [英] SpringMVC RequestMapping for GET url parameters
问题描述
如何使RequestMapping处理url中的GET参数?例如我有这个网址
How to make the RequestMapping to handle GET parameters in the url? For example i have this url
localhost:8080/MyApplication/spm/gcNkyLXkwv
localhost:8080/MyApplication/spm/gcNkyLXkwv
如何从上述网址获取spm值
how to get the spm value from the above url
推荐答案
可以使用PathVariable完成此操作.我将举个例子.您可以将其合并到示例中
This can be done using PathVariable. I will just give example how it can be done. You can incorporate in your example
假设您想写一个URL来获取某些订单,您可以说
Suppose you want to write a url to fetch some order, you can say
www.mydomain.com/order/123
其中 123
是orderId.
where 123
is orderId.
所以现在您将在spring mvc控制器中使用的网址看起来像
So now the url you will use in spring mvc controller would look like
/order/{orderId}现在可以将订单ID声明为路径变量
/order/{orderId} Now order id can be declared a path variable
@RequestMapping(value = " /order/{orderId}", method=RequestMethod.GET)
public String getOrder(@PathVariable String orderId){
//fetch order
}
如果您使用网址 www.mydomain.com/order/123
,则 orderId
变量将在春季之前由值123填充
if you use url www.mydomain.com/order/123
, then orderId
variable will be populated by value 123 by spring
还要注意,PathVariable与requestParam不同,因为pathVariable是URL的一部分.使用请求参数的相同网址看起来像 www.mydomain.com/order?orderId=123
Also note that PathVariable differ from requestParam as pathVariable are part of URL. The same url using request param would look like www.mydomain.com/order?orderId=123
这篇关于用于GET url参数的SpringMVC RequestMapping的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!