select下拉框之数据回显 解析之源码

在日常的项目开放中,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";
	}

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值