select下拉框数据回显

前台页面

<select class="select" name="operatorId" id="operatorId" style="height: 21px;" >
                    <option value="">所属运营商</option>
                    <c:forEach items="${operatorList}" var="operator">
                        <option value="${operator.operatorId}" <c:if test="${operator.operatorId==operatorId}">selected </c:if> >${operator.operatorName}</option>                        
                    </c:forEach>
                </select>

后台用ModelMap  来回显到前台页面上.

public String advertisingList(HttpServletRequest request, ModelMap model) {
        //这个map是传入的值,进行查询.
        Map<String, Object> map = new HashMap<>();
        String operatorId = request.getParameter("operatorId");
        String adClass = request.getParameter("adClass");
        String adName = request.getParameter("adName");
        map.put("operatorId", operatorId);
        map.put("adClass", adClass);
        map.put("adName", adName);
        //查询所有广告位,进行分页查询.
        PageUtil page = this.buildParam(request, map);
        
        List<Map<String,Object>> operatorList=operatorService.getAllOperator();
        model.put("operatorList", operatorList);
        
        List<ChargeAdDTO> chargeAdList = chargeAdService.selectAllChargeAdForPage(map);
        model.put("chargeAdList", chargeAdList);
        //前台数据回显
        model.put("operatorId", operatorId);
        model.put("adClass", adClass);
        model.put("adName", adName);
        model.put("pageBar", page.getToolsMenu());
        return "/manage/advertising/advertising_list";
    }

静态数据回显:

 <span class="select-box inline radius" >
                <select class="select" id="adClass" name="adClass" style="height: 21px;width:100px">
                    <option value='' >广告位类型</option>
                    <option value='0'>图片轮播</option>
                    <option value='1'>视频轮播</option>
                </select>
            </span>

$(function(){
$("#adClass").find("option[value='${adClass}']").attr("selected",'selected');
})

文本框的话,直接加上,value="{}"就好了.

<input type="text" class="input-text radius" style="width:150px" placeholder="请输入广告位名称"  name="adName" id="adName" value="${adName}">

 

posted @ 2019-03-04 14:13  陆伟  阅读(21895)  评论(0编辑  收藏  举报