Spring 仅返回查询字符串中的第一个参数,缺少后续参数。
使用 curl 调用以下 URL 时:
curl -i -X GET -b usercookie.txt -c usercookie.txt http://localhost:8080/appname/users/user-id/campaigns?title=JSON&itemPerPage=5&page=0&orderBy=startDate
只有title
参数有非空值,request.getQueryString()
只包含“title=JSON”
调用这个时:
curl -i -X GET -b usercookie.txt -c usercookie.txt http://localhost:8080/appname/users/user-id/campaigns?page=0&title=JSON&itemPerPage=5&orderBy=startDate
仅包含“ request.getQueryString()
page=0”
控制器代码:
@Controller
public class Campaign {
...
@RequestMapping(value = {"/users/{userId}/campaigns", "/users/{userId}/campaigns/"},
method = RequestMethod.GET)
@ResponseBody
public CampaignListResponse getCampaignList(
@PathVariable(value="userId") String reqUserId,
@RequestParam(required=false) Integer page,
@RequestParam(required=false) Integer itemPerPage,
@RequestParam(required=false) String orderBy,
@RequestParam(required=false) String status,
@RequestParam(required=false) String title,
HttpServletRequest request,
HttpServletResponse response,
@CookieValue("session") String session) {
LOGGER.debug("reqUserId:{} page:{}, itemPerPage:{}, orderBy:{}, state:{}, title:{}", reqUserId, page, itemPerPage, orderBy, status, title);
LOGGER.debug("query string:{}", request.getQueryString());
...
这可能是什么原因?我希望以下所有参数在 request.getQueryString() 和单个 @RequestParam 变量中都有一个值:
page=0&title=JSON&itemPerPage=5&orderBy=startDate
编辑春季版本:3.2.2