爱程序网

springmvc数组参数传递

来源: 阅读:

在开发中遇到将form中的name值一样的多个input元素传递到后台,我用的是springmvc。

刚开始的时候老是报400的请求错误。后来查了下资料,其实解决方案挺简单的。

我的后台controller的代码如下:

 1 @RequestMapping(value = { "/examine" }, produces = "text/html;charset=UTF-8")
 2     @ResponseBody
 3     public String examine(
 4             @RequestParam(value="score") String[] score
 5            ) {
10         try { //
11            System.out.println(score.length);
         return JSONUtils.toJSON("0000", "审核成功!");
18         } catch (Exception e) {
19             e.printStackTrace();
20             logger.error("发生了意外?意外信息:" + e.fillInStackTrace());
21             return JSONUtils.toJSON("9999", "发生了意外?意外信息:" + e.getMessage());
22         }
23     }

前台的代码很简单

<form action="examine" method="post">
       <input name="score" type="text"/>
       <input name="score" type="text"/>
       <input name="score" type="text"/>   
       <input name="score" type="text"/>
        <input name="提交" type="submit"/>
</form>    

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助