我在Spring @controller中写了这个请求的映射,它接受请求和参数“tipoLista,numPagina”
@RequestMapping(value = "/admin/evento/approvatutti", params = "{tipoLista,numPagina}", method = RequestMethod.GET)
public ModelAndView approvaTuttiGliEventi(@RequestParam("tipoLista") String tipoLista, @RequestParam("numPagina") String numPagina, ModelAndView model) {
....bla bla ...bla...
}
当我致电localhost:8084/context/admin/evento/approvatutti?tipoLista=valueOfParameter&numPagina=0
我收到错误代码400,请求错误。我已启用TRACE级别日志记录,但收到此消息:
Resolving exception from handler [null]: org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "{tipoLista,numPagina}" not met for actual request parameters: tipoLista={approvabili}, numPagina={0}
DEBUG - nseStatusExceptionResolver - Resolving exception from handler [null]: org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "{tipoLista,numPagina}" not met for actual request parameters: tipoLista={approvabili}, numPagina={0}
DEBUG - ltHandlerExceptionResolver - Resolving exception from handler [null]: org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "{tipoLista,numPagina}" not met for actual request parameters: tipoLista={approvabili}, numPagina={0}
答案 0 :(得分:5)
The params
attribute of @RequestMapping
expects a String[]
with
任何环境的格式相同:一系列“myParam = myValue”样式 表达式
因此数组中的每个String
的格式为
paramName=paramValue
但您可以省略=paramValue
。但是您提供了一个String
值,如
{tipoLista,numPagina}
这意味着请求查询字符串必须看起来像
?{tipoLista,numPagina}=someValue
这显然没有意义,Spring抱怨
Resolving exception from handler [null]: org.springframework.web.bind.UnsatisfiedServletRequestParameterException: Parameter conditions "{tipoLista,numPagina}" not met for actual request parameters: tipoLista={approvabili}, numPagina={0}
相反,您可以将其更改为
params = {"tipoLista","numPagina"}
但这不是必需的。一起摆脱params
属性。您的方法中已经有@RequestParam
个参数,这些参数是必需的。