[英]Spring MVC RequestParam with optional value
我有一个类似于以下内容的请求映射:
@RequestMapping(value = "/init/filter/", method = RequestMethod.POST)
@ResponseBody
public final Reponse filterGrid(
@RequestParam(value = "nom", required = false) final String nom,
@RequestParam(value = "matricule", required = false) final String matricule,
final HttpServletRequest httpRequete,
final HttpServletResponse httpReponse, Model model) {
}
在我的JavaScript中,我有以下URL:
POST http://localhost:8080/project/pages/rest/consultation/bulletinhorscontrat/init/filter/nom=test 404 (Introuvable)
我找不到页面
我已经用GET尝试过,但遇到了同样的错误
我在Spring MVC方法中忘记了什么?
谢谢
使用post方法时,您不能在链接上传递变量,而应使用@RequestBody
。
但是就您而言,Get方法应该可以完成工作,即使如此,您仍然需要更改链接格式,这里是新链接:
http://localhost:8080/project/pages/rest/consultation/bulletinhorscontrat/init/filter?nom=t&matricule=mat
从链接中删除最后一个/,因为它没有意义,然后将POST更改为Get:
@RequestMapping(value = "/init/filter", method = RequestMethod.GET)
public final Reponse filterGrid(
@RequestParam(value = "nom", required = false) final String nom,
@RequestParam(value = "matricule", required = false) final String matricule,
final HttpServletRequest httpRequete,
final HttpServletResponse httpReponse, Model model) {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.