springmvc checkboxes 回显问题

本博客展示了如何在Java中查询特定渠道列表,处理渠道名称,将处理后的渠道信息与用户对象整合,并返回包含渠道选项的编辑页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

**.java
pubic String test(Model model,User user,HttpServletRequest request,HttpServletResponse response,String channel) {

List<User> ctList = querylist(channel);
        String s= tntProm.getDistributor();
        List<String> list = new ArrayList<String>();
        if(s!=null && !s.equals("")) {
            String[] s = s.split(",");
            for(String temp : s) {
                if(temp != null &&temp.length() != 0){
                    list.add(temp);
                }
            }
        }

Map<String, String> map_id = new HashMap<String, String>();
        String tempId = "";
        String tempName = "";
        for(int i = 0;i<ctList.size();i++) {
            tempId = String.valueOf(ctList.get(i).getUserId());
            tempName = ctList.get(i).getRealName();
            map_id.put(tempId,tempName);
        }
        //user是po对象,其中list是传到前台需要自动勾选的,而map是所有的复选框选项
        user.setList(list);
        model.addAttribute("user", user);
        model.addAttribute("map", map_id);
        return "/test/edit";
}
.jsp
<table >
                    <tbody>
                        <tr>
                            <td>关键词:</td>
                            <td><sf:input path="key" onfocus="this.blur()"/></td>
                        </tr>
                        <tr>
                            <td>ID:</td>
                            <td><sf:input path="id" id="id"/></td>
                        </tr>
                        <tr>
                            <td><span>渠道:&nbsp;&nbsp;&nbsp;&nbsp;</span></td>
                            <td><sf:checkboxes items="${map}" path="list" cssClass="required"/></td>
                        </tr>
                    </tbody>
                </table>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值