java中layui关于数据表格返回Json数据中已经设置 LAY_CHECKED为true但是表格未默认选中的问题
直接说明,在实体类中,使用set方法存值会使得LAY_CHECKED字段名在编译时下划线前的字段变为小写,lay_CHECKED,从而导致无法选中


解决办法:将要传的值使用map封装起来
代码:
/**
* 用户分配角色弹出层的数据回显,复选框选中
*/
@Override
public JsonResult findRoleListAndCh(Integer page, Integer limit, String name, Integer userId) {
int startIndex=(page-1)*limit;
int count=roleMapper.roleCount(name);
List<Role> roleList = roleMapper.selectRoleListByName(startIndex, limit, name);
List<Integer> roleIds=userRoleMapper.selectRoleIdByUserId(userId);
ArrayList<Map<String,Object>> roect = new ArrayList<>();
for (Role ro : roleList) {
Boolean LAY_CHECKED=false;
for (Integer i : roleIds) {
if(ro.getRoleId()==i) {
LAY_CHECKED=true;
}
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("roleId", ro.getRoleId());
map.put("name", ro.getName());
map.put("noteq", ro.getNote());
map.put("LAY_CHECKED", LAY_CHECKED);
roect.add(map);
}
JsonResult rolectList=new JsonResult(roect);
rolectList.setCount(count);
return rolectList;
}

探讨了在Java中使用layui数据表格时,如何正确设置和返回JSON数据以实现表格项默认选中状态的问题。文章指出实体类中使用set方法可能导致字段名编译时变形,提出使用Map封装数据作为解决方案。
2071

被折叠的 条评论
为什么被折叠?



