1.biz Service
//3.修改报销单
void update(ClaimVoucher claimVoucher, List<ClaimVoucherItem> items);
2.Impl
public void update(ClaimVoucher claimVoucher, List<ClaimVoucherItem> items) {
claimVoucher.setNextDealSn(claimVoucher.getCreateSn());
claimVoucher.setStatus(Contant.CLAIMVOUCHER_CREATED);
claimVoucherDao.update(claimVoucher);
List<ClaimVoucherItem> olds = claimVoucherItemDao.selectByClaimVoucher(claimVoucher.getId());
for(ClaimVoucherItem old:olds){
boolean isHave=false;
for(ClaimVoucherItem item:items){
if(item.getId()==old.getId()){
isHave=true;
break;
}
}
if(!isHave){
claimVoucherItemDao.delete(old.getId());
}
}
for(ClaimVoucherItem item:items){
item.setClaimVoucherId(claimVoucher.getId());
if(item.getId()>0){
claimVoucherItemDao.update(item);
}else{
claimVoucherItemDao.insert(item);
}
}
}
3.Contoller
@RequestMapping("/to_update")
public String toUpdate(int id,Map<String,Object> map){
map.put("items", Contant.getItems());
ClaimVoucherInfo info =new ClaimVoucherInfo();
//报销单的基本对象
info.setClaimVoucher(claimVoucherBiz.get(id));
//报销单的详细信息
info.setItems(claimVoucherBiz.getItems(id));
map.put("info",info);
return "claim_voucher_update";
}
@RequestMapping("/update")
public String update(HttpSession session, ClaimVoucherInfo info){
Employee employee = (Employee)session.getAttribute("employee");
info.getClaimVoucher().setCreateSn(employee.getSn());
claimVoucherBiz.update(info.getClaimVoucher(),info.getItems());
return "redirect:deal";
}
4.JSP![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/468350d61990dbbaab7f991357382fe9.png)
在页面上首先要显示之前的信息
<c:forEach items="${info.items}" varStatus="sta">
<div>
<div class="col-md-3">
<label for="items[${sta.index}].item" class="field prepend-icon">
<form:hidden path="items[${sta.index}].id"/>
<form:hidden path="items[${sta.index}].claimVoucherId"/>
<form:select path="items[${sta.index}].item" cssClass="gui-input" placeholder="花销类型..." items="${items}"/>
</label>
</div>
<div class="col-md-3">
<label for="items[${sta.index}].amount" class="field prepend-icon">
<form:input path="items[${sta.index}].amount" cssClass="gui-input money" placeholder="金额..."/>
<label for="items[${sta.index}].amount" class="field-icon">
<i class="fa fa-lock"></i>
</label>
</label>
</div>
<div class="col-md-5">
<label for="items[${sta.index}].comment" class="field prepend-icon">
<form:input path="items[${sta.index}].comment" cssClass="gui-input" placeholder="备注..." />
<label for="items[${sta.index}].comment" class="field-icon">
<i class="fa fa-lock"></i>
</label>
</label>
</div>
<div class="col-md-1" style="text-align:right;">
<button type="button" class="button"> X </button>
</div>
</div>
</c:forEach>
有问题