Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc SpringMVC根据数据库中的数据动态设置要检查的复选框_Spring Mvc_Jsp_Jstl - Fatal编程技术网

Spring mvc SpringMVC根据数据库中的数据动态设置要检查的复选框

Spring mvc SpringMVC根据数据库中的数据动态设置要检查的复选框,spring-mvc,jsp,jstl,Spring Mvc,Jsp,Jstl,我在尝试根据SpringMVC中数据库返回的值设置复选框时遇到了一些问题。基本上我有两组数组,一组包含由ID标识的复选框数据的完整列表,另一组只包含ID本身。我要做的是首先循环显示复选框数据的完整列表,然后循环仅包含ID的数组,如果ID匹配,则将复选框设置为选中 我的控制器类: // list to get full list of checkbox data to be displayed List changeOfParticularsReasons = batchCardApplicati

我在尝试根据SpringMVC中数据库返回的值设置复选框时遇到了一些问题。基本上我有两组数组,一组包含由ID标识的复选框数据的完整列表,另一组只包含ID本身。我要做的是首先循环显示复选框数据的完整列表,然后循环仅包含ID的数组,如果ID匹配,则将复选框设置为选中

我的控制器类:

// list to get full list of checkbox data to be displayed
List changeOfParticularsReasons = batchCardApplication.getBatchChangeOfParticularList(reasonReplacementId);
model.addAttribute("changeOfParticularsList", changeOfParticularsReasons);

// list to get the ID to be checked, it is just a string array with IDs
String[] changeParticularsDetailTOArray = new String[changeParticularsDetailTOList.size()];
for(int i = 0; i < changeParticularsDetailTOList.size(); i++){
    ChangeParticularsDetailTO changeParticularsDetailTO = (ChangeParticularsDetailTO) changeParticularsDetailTOList.get(i);
    changeParticularsDetailTOArray[i] = String.valueOf(changeParticularsDetailTO.getChangedParticularId());
}
model.addAttribute("selected", changeParticularsDetailTOArray);
//获取要显示的复选框数据的完整列表的列表
List ChangeOfParticularReasons=batchCardApplication.getBatchChangeOfParticularList(reasonReplacementId);
addAttribute(“特定列表的更改”,特定原因的更改);
//列表来获取要检查的ID,它只是一个带有ID的字符串数组
String[]ChangeSpecialsDetailToArray=新字符串[ChangeSpecialsDetailToList.size()];
对于(int i=0;i
我的JSP:

<c:if test="${!empty selected}">
        <c:forEach var="change" items="${changeOfParticularsList}" varStatus="theIndex"> 
            <tr>
                <td align="left" width="5%">
                    <input type="checkbox" name="selected" 
                            value="${change.replacementTypeID}" ${(newDisabled == true) ? 'disabled' : ''} />  
                            
                    <c:forEach var="selectedItem" items="${selected}"> 
                        <c:if test="${selectedItem == change.replacementTypeID}">
                            <input type="checkbox" name="selected" checked
                                    value="${change.replacementTypeID}" ${(newDisabled == true) ? 'disabled' : ''} />  
                        </c:if>
                    </c:forEach>
                    
                </td>
                
                <td align="left" width="95%">
                    <c:out value="${change.replacementType}" />
                </td>       
            </tr>
        </c:forEach>
    </c:if>

我得到的是:

有没有办法解决这个问题?ID的值仅为1到10。谢谢