JSP中标签的使用

时间:2022-11-01 23:33:55

JSP中<%@taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>的使用
前端代码

  • 注:subsidyType与返回的ConstantDict的对象的constantDict.id对应
<div class="form-group">
<label for="subsidyType" class="col-sm-3 control-label">补贴类型</label>
<div class="col-sm-9">
<select class="form-control" id="subsidyType" name="subsidyType">
<c:forEach var="constantDict" items="${constantDicts}">
<option value="${constantDict.id}">${constantDict.constantName}</option>
</c:forEach>
</select>
</div>
</div>

后端代码
需要给前台返回一个List

@RequestMapping
public ModelAndView showDefaultPage() {
List<ConstantDict> constantDicts = constantDictBiz.findByConstantTypeCode("subsidy_type");
ModelAndView mav = new ModelAndView();
mav.setViewName(defaultPage);
mav.addObject("constantDicts", constantDicts);
return mav;
}