一、在追加商品库存时,只显示还没有库存的商品
1、在stockList中点击 <a class="btn btn-success" href="initAddStock">
<i class="glyphicon glyphicon-zoom-in icon-white"></i> 追加</a>
2、在Controller对应的路径写下列代码:
@RequestMapping(value = "initAddStock", method = RequestMethod.GET)
public String initAddStock(Model model) {
log.info("追加库存单据初始化");
List<Item> commodityList = itemListComponent.getSurCommodityList();
model.addAttribute("commodityList", commodityList);
StockForm stockForm = new StockForm();
model.addAttribute("stockForm", stockForm);
return "manager/stock/addStock";
}
3、在ItemListComponent进行下列处理
public List<Item> getSurCommodityList() {
return queryDao.executeForObjectList("Common.selectSurCommodity", null);
}
4、对应的sql文为
<select id="selectSurCommodity" parameterClass="java.lang.String"
resultClass="cn.agriculture.web.form.Item">
SELECT commodity_name as label,
commodity_id as value
FROM commodity
<isNotNull property="value">
WHERE brand_id = #value#
</isNotNull>
WHERE not exists(
SELECT stock.commodity_id
FROM stock
WHERE stock.commodity_id = commodity.commodity_id)
</select>
5、在出错时在addStock中要获得正确的值
List<Item> commodityList = itemListComponent.getSurCommodityList();
二、编辑商品信息并实现修改
1、在stockList中点击<a class="btn btn-info" href="initEditStock?stockId=${stockInfo.stockId}">
<iclass="glyphicon glyphicon-edit icon-white"></i> 编辑</a>
2、在Controller对应的路径写下列代码:
@RequestMapping(value = "initEditStock", method = RequestMethod.GET)
public String initEditStock(Model model, StockForm stockForm) {
log.info("修改库存单据信息初始化");
StockForm result = itemListComponent.getEditCommodity(stockForm);
model.addAttribute("stockForm", result);
return "manager/stock/editStock";
}
3、在ItemListComponent进行下列处理
public StockForm getEditCommodity(StockForm frm) {
return queryDao.executeForObject("Stock.selectEditCommodity", frm,StockForm.class);
}
4、对应的sql文为
<select id="selectEditCommodity"
parameterClass="cn.agriculture.web.form.StockForm"
resultClass="cn.agriculture.web.form.StockForm">
select stock_id as stockId,
commodity.commodity_id as commodityId,
commodity.commodity_name as commodityName,
stock.stock as stock,
stock.note as note
from stock,commodity
where stock.commodity_id = commodity.commodity_id
and stock.stock_id = #stockId#
</select>
5、在edit页面要hidden形式把Id和Name到stockForm,这样在出错的情况的才能获得Id和Name
<input type="hidden" name="commodityId" value="${stockForm.commodityId}"/>
<input type="hidden" name="commodityName" value="${stockForm.commodityName}"/>