在日常的项目开放中,select下拉框之数据回显,页面上用到这一方面的挺多。
今天小弟在此奉上
jsp页面中,使用<c:if test=" 条件判断"></c:if>
<form id="form1" action="selectPaperState" method="post" name="PagerShowInfo">
<input id="tplanId" name="tplanId" type="hidden">
<input type="hidden" id="pageNum" name="pageNum">
<div class="title_right">
<span class="pull-right margin-bottom-5">
<select class="js-example-data-array" style="height:28px" id="paperState" name="paperState">
<option value="-1" <c:if test="${'-1' eq state}">selected</c:if>>请选择试卷状态</option>
<option value="1" <c:if test="${'1' eq state}">selected</c:if>>1.已开始训练试卷</option>
<option value="0" <c:if test="${'0' eq state}">selected</c:if>>2.未开始训练试卷</option>
</select>
<input class="btn btn-info btn-small" type="submit" value="搜索">
</span> <strong>试卷列表</strong>
</div>
</form>
在@Controller中,需要将state的状态信息放在model模型中,在页面中获取对比值,
@RequestMapping("/selectPaperState")
public String selectPaperState(Model model,HttpServletRequest request) {
Map<String, Object> user = (Map<String, Object>) request.getSession().getAttribute("user");
String userId = (String) user.get("userId");
String state = request.getParameter("paperState");
List<TestPlan> testPlan = null;
if("-1".equals(state)){
testPlan = paperShowService.findByProperty(userId);
}else{
testPlan = paperShowService.selectPaperState(userId,state);
}
model.addAttribute("state", state);
model.addAttribute("testPlan", testPlan);
return "paperdesign/paperShowList";
}