码迷,mamicode.com
首页 > 编程语言 > 详细

Java 单向关联表,保存更新数据

时间:2017-10-18 23:17:38      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:java 单向关联表   保存更新数据   

BService.java

public Bsave(Bb, HttpServletRequest request) {

b.setRecordInfo(super.GenRecordInfo(b.getRecordInfo(), request));

b= bDao.save(b);

try {

zService.saveByZfcg(b, request);

} catch (Exception e) {

e.printStackTrace();

}

return b;

}



ZService.java

public Z dtl(int refnum, String applyTo) {

String hql = "FROM Z WHERE  refnum =? and  applyTo =?";

List<Object> args = new ArrayList<Object>();

args.add(refnum);

args.add(applyTo);

return zDao.dtl(hql, args);

}


// 保存数据

public void saveByZfcg(B b, HttpServletRequest request) {

Z z = new Z();

Z z1 = dtl(b.getId(), "B ");// 查看

if (z1 != null) {                              //判断表中是否有采购的id,和"B ",

z1 .setProject_Code(b.getBid_Code()); //有就更新这条记录

z1 .setProject_Code(b.getBid_Code()); //

z1 .setProject_Name(b.getBid_Name());

z1 .setProject_Type("采购");

z1 .setProject_Publish_Time(b.getRecordInfo().getCreatedAt());

z1 .setPublish_Time(b.getRecordInfo().getCreatedAt());

z1 .setTrade_Time(b.getKbsj());

z1 .setApplyTo("B ");

z1 .setRefnum(b.getId());

save(z1 , request);

} else {

z.setProject_Code(b.getBid_Code());// 存入对应的字段(没有就保存一条)

z.setProject_Name(b.getBid_Name());

z.setProject_Type("采购");

z.setProject_Publish_Time(b.getRecordInfo().getCreatedAt());

z.setPublish_Time(b.getRecordInfo().getCreatedAt());

z.setTrade_Time(b.getKbsj());

z.setApplyTo("B ");

z.setRefnum(b.getId());

save(z, request);

}


}


本文出自 “砥身砺行” 博客,请务必保留此出处http://82711020.blog.51cto.com/12993840/1973938

Java 单向关联表,保存更新数据

标签:java 单向关联表   保存更新数据   

原文地址:http://82711020.blog.51cto.com/12993840/1973938

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!