从一个控制层返回的jsp页面,在jsp页面中有一个下拉框需要去选择后台的值
1.需要在控制层返回一个list集合,后台对象的集合
@RequiresPermissions("mytreemould:myTreeMould:view") @RequestMapping(value = { "list", "" }) public String list(MyTreeMould myTreeMould, HttpServletRequest request, HttpServletResponse response, Model model) { Page<MyTreeMould> page = myTreeMouldService.findPage(new Page<MyTreeMould>(request, response), myTreeMould); model.addAttribute("page", page); //获取下拉列表中的数据,每一个对象都放在list集合中,传到前台,在前台获取 List<MyTreeMould> list =myTreeMouldService.findList(new MyTreeMould()); List<MyTreeMould> list1=new ArrayList<MyTreeMould>(); for(MyTreeMould my:list) { list1.add(my); System.out.println(")))))"+my.getMouldName()); } //给值传回前台 model.addAttribute("list1",list1); return "modules/mytreemould/myTreeMouldList"; }
2.前端进行对list集合处理
<form:form id="searchForm" modelAttribute="myTreeMould" action="${ctx}/mytreemould/myTreeMould/createfile" method="post" class="breadcrumb form-search"> <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/> <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/> <ul class="ul-form"> <li><label>选择的模版:</label> <%-- <form:input path="mouldName" htmlEscape="false" maxlength="64" class="input-medium"/> --%> <form:select id="mouldname" path="mouldName" class="input-xlarge required" itemValue=""> <form:option value="" id="" label="--请选择--"></form:option> <form:options items="${list1}" itemValue="mouldName" itemLabel="mouldName" ></form:options> </form:select> </li> <li><label>是否使用:</label> <form:select path="mouldIs" class="input-medium"> <form:option value="" id="" label="--请选择--"></form:option> <form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/> </form:select> </li> <li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="创建"/></li> <li class="clearfix"></li> </ul> </form:form>
其中,主要代码
<form:select id="mouldname" path="mouldName" class="input-xlarge required" itemValue=""> <form:option value="" id="" label="--请选择--"></form:option> <form:options items="${list1}" itemValue="mouldName" itemLabel="mouldName" ></form:options> </form:select>
效果