modelAttribute(对象列表)在Spring MVC中随机返回null参数

时间:2014-04-08 16:32:19

标签: spring-mvc spring-mvc-initbinders

我是Spring MVC的新手,我很难调试这个问题。我从我的数据库中获取一些细节,并从我的控制器发送到JSP,我能够正确显示它。当我尝试将相同的表单提交回控制器进行某些测试时,很少有属性值为空。

class Quote(){
    int id;
    String name;
    //getters and setter
}

class QuotesForm(){
    List<Quote> quotesList = new ArrayList<Quote>();
    //getters and setters
}


@Controller
class TestController{

        @RequestMapping(value = "/update_quotes", method = RequestMethod.POST)
        public String updateQuotes(@ModelAttribute("quotesForm") QuotesForm quotesForm,
                ModelMap model,
                HttpServletRequest request) {
            logger.info("update quotes method invoked");
            logger.info("quotesForm size " + quotesForm.getQuotesList().size());

            for (Quote quote : quotesForm.getQuotesList()) {
                logger.info(quote.getId() + " , " + quote.getName());
             }
           return "/list_quotes";
          }
}

这是我的jsp(预览)

    <form:form id="quotes_form" action="${pageContext.request.contextPath}/update_quotes" method="post" modelAttribute="quotesForm">
        <table>
            <c:forEach items="${quotesForm.quotesList}" var="quote" varStatus="status">
                <tr>
                    <td>    <form:input path="verticalsList[${status.index}].id" value="${quote.id}"/></td>
                    <td>   <form:input path="quotesList[${status.index}].name" value="${quote.name}" readonly="true"/></td>
                </tr>
            </c:forEach>
            <tr>
            <td colspan="2"> <input type="submit" value="Update" onclick='$("#quotes_form").submit();' /> </td>
            <tr>
        </table>
    </form:form>

这是我的控制器日志

2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1223 , Think like a proton... always positive...
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1224 , The best feeling on earth is love, and the worst feeling on earth is death...
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1225 , You cannot hide from yourself...
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1226 , null
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1227 , null
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1228 , null
2014-04-08 10:56:18,486 [http-bio-8080-exec-8] INFO  ui.controller.TestController  - 1229 , null

请帮助我理解并解决问题,如果您需要进一步的信息

1 个答案:

答案 0 :(得分:0)

只是为了让别人知道;我详细检查了我的日志,发现实际问题是tomcat容器在给定的GET / POST请求中无法处理超过10000个键/参数值对。 我引用了这个link并将maxParameterCount =“100000”添加到我的tomcat server.xml中,它解决了这个问题。