如何將數據放入下拉框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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM