hibernate一对多保存完整实现
一对多保存,一是入库单storage,多是物品列表goods,store中保存的是一个goods数组,storagestore中放的是所有goods的信息和storage信息提交到后台?
?? 1)、从列表中取出数据往store中添加数据
???????
迭代器的使用String goods = request.getParameter("goods");JSONArray js=JSONArray.fromObject(goods);Iterator it=js.iterator();it.hasNext//用来判断是否还有对象数据,返回Booleanit.next()//用来取到下一个对象数据jo=(JSONObject)it.next();
?
先记录一下....
public String saveStorage(){
??? ? try {
??? ?? ConStorage conStorage = new ConStorage();
??? ?? String goods = request.getParameter("goods");
??? ?? JSONArray js=JSONArray.fromObject(goods);
??? ?? JSONObject jo=null;
??? ?? Iterator it=js.iterator();
??? ??? while(it.hasNext()){? ?
??? ???? ?? ConGoods conGoods = new ConGoods();
??? ???????? jo=(JSONObject)it.next();
??? ???????? String goodId=jo.getString("goodsname");??? ????????
?????? ??????????? String goodIddd=jo.getString("goodsname");
?????? ???? ??? System.out.println(goodIddd);
?????? ??????????? conStorage.setStorekeep(goodIddd);
?????? ???????????
??? ???? ??? System.out.println(goodId);
??? ??????????? conGoods.setGoodsname(goodId);
??? ???? ??? conGoods.setConStorage(conStorage);
??? ??????????? conGoodsall.add(conGoods);
??? ??? }
??? ?? System.out.println(conGoodsall.size());?? ???
??? ?? conStorage.setConGoods(conGoodsall);
??? ?? conStorageService.save(conStorage);
??? ?? return SUCCESS;
??} catch (Exception e) {
???e.printStackTrace();
???return INPUT;
??}
???? }