不满意的ServletRequestParameterException spring控制器没有映射请求,错误400

时间:2014-02-16 16:58:12

标签: java spring spring-mvc

我在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}

1 个答案:

答案 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个参数,这些参数是必需的。