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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 10:49:17  来源:igfitidea点击:

UnsatisfiedServletRequestParameterException spring controller don't mapping request, error 400

javaspringspring-mvc

提问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 paramsattribute of @RequestMappingexpects a String[]with

params属性@RequestMapping期望String[]

Same format for any environment: a sequence of "myParam=myValue" style expressions

适用于任何环境的相同格式:一系列“myParam=myValue”样式表达式

So each Stringin the array is of the format

所以String数组中的每个都是格式

paramName=paramValue

but you can omit the =paramValue. But you are providing a single Stringvalue 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 paramsattribute all together. You already have @RequestParamparameters in your method which are required.

但这不是必需的。params一起去掉属性。您@RequestParam的方法中已经有需要的参数。