从jsp向控制器发送列表

qni6mghb  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(291)

我试图将列表从jsp发送到控制器,我使用的是SpringMVC
clausedtotest类

public class ClauseDtoTest {

    private Integer clauseId;
    private Integer version;
    private String title;
    private String description;

    //Constructors getters setters and toString method
}

formbean类

public class FormBean {

    List<ClauseDtoTest> clauseDtoTests;

   //Constructors getters setters and toString method
}

jsp表单提交方法

<form:form method="POST" class="form-horizontal" modelAttribute="formBean" action="${pageContext.request.contextPath}/work_flow/clause/reject/all/${wrkflwid}">

      <form:input path="clauseDtoTests" type="hidden" value="${clauseDtoTests}"/>

      <button type="submit" class="btn btn-success">Approve All</button>

</form:form>

控制器

@RequestMapping(value = "/clause/reject/all/{wrkflwid}", method = RequestMethod.POST)
public String rejectAllClause(@ModelAttribute("formBean") FormBean formBean, @PathVariable("wrkflwid") int wrkflwid, Model model) {

}

当我点击提交按钮,我得到下面的错误

WARN : org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Handler execution resulted in exception: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'formBean' on field 'clauseDtoTests': rejected value [[{clauseId=1, version=3, title='null', description='null'}, {clauseId=2, version=4, title='null', description='null'}, {clauseId=4, version=3, title='null', description='null'}]]; codes [typeMismatch.formBean.clauseDtoTests,typeMismatch.clauseDtoTests,typeMismatch.java.util.List,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [formBean.clauseDtoTests,clauseDtoTests]; arguments []; default message [clauseDtoTests]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.List' for property 'clauseDtoTests'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [entity.ClauseDtoTest] for property 'clauseDtoTests[0]': no matching editors or conversion strategy found]

将列表从jsp发送到控制器的正确方法是什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题