七月二十九(1)

在StockController里

@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";

    }

@RequestMapping(value = "addStock", method = RequestMethod.POST)

public String executeAddStock(Model model, HttpSession session, @Valid @ModelAttribute("stockForm") StockForm stockForm, BindingResult results) throws SQLException, IOException {

if (results.hasErrors()) {

log.info("添加库存单据信息");

List<Item> commodityList = itemListComponent.getSurCommodityList();   //追加库存信息失败时,要重新获取一次剩余商品信息

   model.addAttribute("commodityList", commodityList);

model.addAttribute("stockForm", stockForm);

       return "manager/stock/addStock";

}

UVO uvo = (UVO)session.getAttribute("UVO");

stockForm.setUpdateUser(uvo.getUserName());

Date date = new Date();

SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

stockForm.setUpdateTime(dateformat.format(date));

boolean result = stockService.addStock(stockForm);

if(!result) {

throw new SQLException("库存单据信息添加失败!");

}

model.addAttribute("list", stockService.searchStockList());

        return "manager/stock/stockList";

}

在ItemListComponent。java里

public List<Item> getSurCommodityList() {

return queryDao.executeForObjectList("Common.selectSurCommodity", null);

}

对应的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

WHERE  not  exists( 

    SELECT stock.commodity_id  FROM stock    WHERE stock.commodity_id = commodity.commodity_id)

</select>


你可能感兴趣的:(七月二十九(1))