重定向到另一个URL对象列表

时间:2014-05-28 12:29:30

标签: spring-mvc

我在MVC控制器中有这个方法

public String save(
        @RequestParam("id") Long id,
        @RequestParam(value = "book", required = false) List<Long> books,
        @RequestParam(value = "bookNow", required = false) List<Long> booksNow) {

    if (booksNow != null)
        return "redirect:/saveNow.html?id=" + id + "&bookNow=" + booksNow;

但问题是,如果对象booksNow列表不为空,我想重定向到另一个方法。

@RequestMapping(value = "/saveNow.html", method = RequestMethod.GET)
public String saveNow(
        @RequestParam("id") Long id,
        @RequestParam(value = "bookNow", required = true) List<Long> booksNow) {

但我有错误

The request sent by the client was syntactically incorrect.

重定向对象列表的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

"&bookNow=" + booksNow没有意义。

booksNow只会打印一些像List @ 1e23

这样的java对象

您需要遍历列表,以便您的网址如下:

"redirect:/saveNow.html?id=123&bookNow=234&bookNow=235&bookNow=236