Java UnsatisfiedServletRequestParameterException spring 控制器不映射请求,错误 400
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21814386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UnsatisfiedServletRequestParameterException spring controller don't mapping request, error 400
提问by carminePat
I have write in my Spring @controller this mapping of request, it accepts request and parameter "tipoLista,numPagina"
我在 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...
}
When i call localhost:8084/context/admin/evento/approvatutti?tipoLista=valueOfParameter&numPagina=0
当我打电话 localhost:8084/context/admin/evento/approvatutti?tipoLista=valueOfParameter&numPagina=0
I received error code 400, bad request. I have enabled TRACE level logging and I receive this message:
我收到错误代码 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}
采纳答案by Sotirios Delimanolis
The params
attribute of @RequestMapping
expects a String[]
with
的params
属性@RequestMapping
期望String[]
与
Same format for any environment: a sequence of "myParam=myValue" style expressions
适用于任何环境的相同格式:一系列“myParam=myValue”样式表达式
So each String
in the array is of the format
所以String
数组中的每个都是格式
paramName=paramValue
but you can omit the =paramValue
. But you are providing a single String
value like
但您可以省略=paramValue
. 但是您提供的是一个单一的String
值,例如
{tipoLista,numPagina}
this would mean the request query string would have to look like
这意味着请求查询字符串必须看起来像
?{tipoLista,numPagina}=someValue
which obviously makes no sense and Spring complains
这显然没有意义,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}
Instead, you can change it to
相反,您可以将其更改为
params = {"tipoLista","numPagina"}
but this is not necessary. Get rid of the params
attribute all together. You already have @RequestParam
parameters in your method which are required.
但这不是必需的。params
一起去掉属性。您@RequestParam
的方法中已经有需要的参数。