将数组或列表传递给@Path变量 - Spring / Java [英] Passing an Array or List to @Pathvariable - Spring/Java
本文介绍了将数组或列表传递给@Path变量 - Spring / Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在JBoss / Spring中做了一个简单的'get'。我希望客户端在url中传递一个整数数组。如何在服务器上进行设置?并显示客户端应该发送消息?
I am doing a simple 'get' in JBoss/Spring. I want the client to pass me an array of integers in the url. How do I set that up on the server? And show should the client send the message?
这就是我现在所拥有的。
This is what I have right now.
@RequestMapping(value="/test/{firstNameIds}", method=RequestMethod.GET)
@ResponseBody
public String test(@PathVariable List<Integer> firstNameIds)
{
//What do I do??
return "Dummy";
}
在客户端我希望传递类似
On the client I would like to pass something like
http://localhost:8080/public/test/[1,3,4,50]
当我这样做时,我收到一个错误:
When I did that I get an error:
java.lang.IllegalStateException:找不到@ @RequestMapping中的PathVariable [firstNameIds]
java.lang.IllegalStateException: Could not find @PathVariable [firstNameIds] in @RequestMapping
推荐答案
GET http://localhost:8080/public/test/1,2,3,4
@RequestMapping(value="/test/{firstNameIds}", method=RequestMethod.GET)
@ResponseBody
public String test(@PathVariable String[] firstNameIds)
{
// firstNameIds: [1,2,3,4]
return "Dummy";
}
(使用Spring MVC 4.0.1测试)
(tested with Spring MVC 4.0.1)
这篇关于将数组或列表传递给@Path变量 - Spring / Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文