数据库读取数据加载下拉框级联的示例

1.在Controller中查询到数据加载到页面中
	@RequiresPermissions("wms:quality:wmsIqcInspect:view")
	@RequestMapping(value = { "getInspect", "" })
	public String getInspect(WmsIqcInspect wmsIqcInspect, HttpServletRequest request, HttpServletResponse response,Model model) {
		Page<WmsIqcInspect> page = wmsIqcInspectService.getInspect(new Page<WmsIqcInspect>(request, response),wmsIqcInspect);
		model.addAttribute("page", page);
		// 新增查询超期物料类别的方法传递给前台页面
		List<WmsMaterialManage> wmmList = wmsMaterialManageService.getItemCategory();
		model.addAttribute("itemCategoryList", wmmList);
		// 新增查询湿敏元器件的方法传递给前台页面
		List<WmsHumidityElement> humidityElementList = wmsHumidityElementService.getItemHumidityElement();
		model.addAttribute("humidityElementList", humidityElementList);
		return "modules/wms/quality/wmsIqcInspectList";
	}
2.在Service中对应的方法
	public List<WmsMaterialManage> getItemCategory() {
		User user = UserUtils.getUser();
		return dao.getItemCategory(user.getFactoryId());
	}
3.在Dao中对应的方法
	public List<WmsMaterialManage> getItemCategory(@Param("factoryId") String factoryId);
4.在xml中对应的方法,给查询出来的字段封装成属性
<select id="getItemCategory" resultType="WmsMaterialManage">		 
	SELECT
		ITEM_CATEGORY AS "itemCategory",
		( CASE WHEN STORAGE_CYCLE IS NOT NULL THEN to_number( STORAGE_CYCLE ) * 30 ELSE to_number( STORAGE_CYCLE_DAY ) END ) AS "storageCycle" 
	FROM
		WMS_RECHECK_CATEGORY 
	<where>
		del_flag = '0' 
		<if test="factoryId != null and factoryId != ''">
			AND factory_id = #{ factoryId }
		</if>
	</where>
</select>
5.在对应的页面中进行数据展示
<script type="text/javascript">
	//新建一个保存数据的变量
	var list_map = new Array();
	$(document).ready(function() {
		//给传递过来的List进行循环,然后封装成键值
		<c:forEach items="${itemCategoryList}"  var = "itemAndCycle"> 
			//expirationDateMap.set("${itemAndCycle.itemCategory}","${itemAndCycle.storageCycle}");
			list_map.push({itemCategory:"${itemAndCycle.itemCategory}",storageCycle:"${itemAndCycle.storageCycle}"}); 
		</c:forEach>
		//选择下拉框的值,绑定另一个文本框的显示值:
		//通过选择超期物料类别 ,得到对应的保质期
		function getExpirationDate(){
			if(reelmount==""){
				$.jBox.info("<spring:message code="jsp.wmsIqcInspectList.p46"/>");     <!---请先选择单列表的数据","系统提示--->
				return false;
			}
			var itemCategoryStyle = $("#itemCategory").find("option:selected").text();
			$("#expirationDate").val("");
			//超期物料类别变化,对应的保质期一起变化
			if(list_map != null && list_map.length > 0){
			  	for ( var i = 0; i < list_map.length; i++){
				  	if(list_map[i].itemCategory == itemCategoryStyle){
					  $("#expirationDate").val(list_map[i].storageCycle);
				  	}
				}
			 }
		 }
	});
</script>

//HMTL页面如下:
<tr>
	<td class="tit"><spring:message code="jsp.wmsMaterialManageForm.p37"/></td><!-- 超期物料类别 -->
	<td>
		<select id="itemCategory" class="select-medium" onchange="getExpirationDate()">
			<option value=""></option>
			<c:forEach items="${itemCategoryList}" var = "itemCategoryList">
				<option value="${itemCategoryList.itemCategory}">${itemCategoryList.itemCategory}</option>
			</c:forEach>
		</select>
	</td>
	<td class="tit"><spring:message code="jsp.wmsMaterialManageForm.p17"/></td><!-- 保质期()-->
	<td>
		<input id="expirationDate" class="input-medium " readOnly="readOnly"/>
	</td>
</tr>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值