1、無重複記錄添加java
一、addExpressPrice.jsp(以列表形式顯示省份列表)web
<td> <div class="controls"> <form:select path="provinceId"> <form:options items="${provinceList}" itemLabel="label" itemValue="value" /> </form:select> </div> </td>
二、ExpressPriceController.java(初始化頁面)express
@RequestMapping(value = "initAddExpressPrice", method = RequestMethod.GET) public String initAddExpressPrice(Model model, ExpressPriceForm expressPriceForm) { log.info("追加快遞商所屬價格初始化"); List<Item> provinceList = itemListComponent.getProvinceList1(expressPriceForm.getExpressId()); model.addAttribute("provinceList", provinceList); model.addAttribute("expressPriceForm", expressPriceForm); return "manager/expressPrice/addExpressPrice"; }
三、ItemListComponent.javaapp
public List<Item> getProvinceList1(String expressId) { return queryDao.executeForObjectList("Common.selectExpressPriceProvince", expressId); }
四、CommonSqlMap.xmljsp
<select id="selectExpressPriceProvince" parameterClass="java.lang.String" resultClass="cn.agriculture.web.form.Item"> SELECT province_name as label,province_id as value FROM province WHERE not exists(SELECT express_price.province_id FROM express_price,express WHERE express_price.province_id=province.province_id AND express.express_id=express_price.express_id AND express.express_id=#value#) </select>
2、省份以列表形式顯示spa
一、addExpressPrice.jspcode
<form:select path="provinceId"> <form:options items="${provinceList}" itemLabel="label" itemValue="value" /> </form:select>
二、ItemListComponent.javaorm
public List<Item> getProvinceList() { return queryDao.executeForObjectList("Common.selectProvince", null); } public String getProvinceLabel(String provinceValue) { return queryDao.executeForObject("Common.selectProvinceLabel", provinceValue, String.class); }
三、CommonSqlMap.xmlxml
<select id="selectProvince" resultClass="cn.agriculture.web.form.Item"> SELECT province_name as label,province_id as value FROM province </select> <select id="selectProvinceLabel" parameterClass="java.lang.String" resultClass="java.lang.String"> SELECT province_name as label FROM province WHERE province_id = #value# </select>