小编sar*_*ran的帖子

如何使用@ModelAttribute将List绑定到JSP表单的控制器

我正在尝试使用@modelAttribute及其各自的id和blurb来获取我的控制器的所选候选者列表.我可以正确地带一个候选人,但我不知道如何通过...我试图添加列表<>,如下所示,但我得到了

错误 - 严重:Servlet [dispatcher]的Servlet.service()在路径[/ panel-requests]的上下文中引发异常[请求处理失败; 嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化bean类[java.util.List]:指定的类是一个具有根本原因的接口] org.springframework.beans.BeanInstantiationException:无法实例化bean类[java.util .List]:指定的类是一个接口

JSP -

<form:form modelAttribute="candidateAddAttribute" 
  action="/panel-requests/requests/${panelRequestForId.id}/empl" method="post">
<c:forEach items="${candidates}" var="candidates">
    <select name="employee" id="employee" disabled="disabled">
        <option value="default" selected="selected">${candidates.candidateName}</option>
    </select>
    <textarea rows="3" cols="40" id="candidateBlurb" name="candidateBlurb" 
      disabled="disabled">${candidates.candidateBlurb}</textarea>

    <textarea rows="2" cols="20" id="candidateCV" name="candidateCV"                                
      disabled="disabled">${candidates.candidateCV}</textarea>
</c:forEach>
<div id="candidateDiv" id="candidateDiv">
    <select name="employee" id="employee">
        <option value="default" selected="selected">Select Employee</option>
        <c:forEach items="${employees}" var="employee">
            <option value="${employee.id}" id="${employee.id}">
                ${employee.employeeName}- ${employee.employeeCV}<
            /option>
        </c:forEach>
    </select>   
    <textarea rows="3" cols="40" id="candidateBlurb"                
      name="candidateBlurb">BLURB</textarea>
    <div id="employeeCv"></div>
    <input type="submit" value="Add Candidate" />
</div>
</form:form>
Run Code Online (Sandbox Code Playgroud)

上面的表格首先显示员工列表,当用户选择员工时,输入blurb并点击添加候选按钮,我将数据带到控制器.

控制器:

@RequestMapping(value = "{id}/empl", method …
Run Code Online (Sandbox Code Playgroud)

java jsp spring-mvc

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

jsp ×1

spring-mvc ×1