如何将数据放入下拉框List值

最近在做下拉框,里面放入值大概有这几种

 

	//仓库业务类型 第一种
		model.addAttribute("warehouseBizTypeList", basePropertyService.loadPropertyDicByPropertyId(PropertyDictionary.WAREHOUSE_BIZ_TYPE));
        //所属客户:分部 第二种
		model.addAttribute("customerBelongedList",customerInfoService.loadBelongedCustomer());

第一种是放入数据字典

/**
	 *  仓库业务类型
	 */
	Long WAREHOUSE_BIZ_TYPE=Long.valueOf(36204456);

 这样warehouseBizTypeList就拥有主键值为36204456所对应的

select * from base_property_dictionary where property_id=36887947

+---------------+-------------+----------------+--------+---------------+
| dictionary_id | property_id | property_value | status | property_code |
+---------------+-------------+----------------+--------+---------------+
|      36886416 |    36204456 | 实体仓          | A      | 1             |
|      36886417 |    36204456 | 虚拟实体仓库          | A      | 2             |
|      36886418 |    36204456 | 虚拟仓            | A      | 3             |
|      36886419 |    36204456 | 逻辑仓         | A      | 4             |
+---------------+-------------+----------------+--------+---------------+
在JSP页面

<td style="vertical-align:middle" align="right" width="10%"><label><span class="redmark">*</span> 仓库业务类型:</label></td>
								<td style="vertical-align:middle" align="left" width="20%">
									<select name="warehouseType" id="warehouseType" style="width:95%">
										<option value="">--请选择--</option>
										 <c:forEach var="bizTypeList" items="${warehouseBizTypeList}" varStatus="s">
								        	<option value="${bizTypeList.propertyCode}" <c:if test="${bizTypeList.propertyCode eq warehouseInfo.warehouseType}">selected="selected"</c:if>>${bizTypeList.propertyValue}</option>
								        </c:forEach>
									</select>
								</td>

 第二种,不用数据字典,通过hibernate find筛选出 List

	@SuppressWarnings("unchecked")
	public List<CustomerInfo> loadBelongedCustomer() {
		String resultSql = "from CustomerInfo t where t.status='A' and t.bussinessType='6'  order by t.isRenter asc";
		//查询租户不需要权限过滤。加如下语句。
		//ThreadLocalClient.get().envParamMap.put(DataAuthority.IS_APPLY_AUTHORITY, false);
		List<CustomerInfo> list = hibernateTemplate.find(resultSql);
		//ThreadLocalClient.get().envParamMap.put(DataAuthority.IS_APPLY_AUTHORITY, null);
		return list;

	}

 对于JSP

<td style="vertical-align:middle" align="right" width="10%"><label><span class="redmark">*</span>所属客户:</label></td>
								<td style="vertical-align:middle" align="left" width="20%">
									<select name="baseBusinessOrg" style="width:95%">
										<option value="">--请选择--</option>
										<c:forEach var="customerBelonged" items="${customerBelongedList}">
											<option value="${customerBelonged.id}"
												<c:if test="${warehouseInfo.customerBelonged.id==customerBelonged.id}"> selected</c:if>><c:out value="${customerBelonged.customerName}"/></option>
										</c:forEach>
									</select>
								</td>

 

posted @ 2014-02-28 09:43  Kstyjobx!!  阅读(5219)  评论(0编辑  收藏  举报