当前位置:编程学习 > JSP >>

JSP代码求助,这个action怎么写

bill(bid,id,b1,b2)和customer(id,c1,c2)是有联系的两张表,BillUpdateAction是一个动作,页面执行后对bill执行更新。BillUpdateAction里面怎么写??代码如下,求完善。 package action; import hiber.HibernateSessionFactory; import hiber.domain.Bill; import hiber.domain.BillDAO; import hiber.domain.Customer; import hiber.domain.CustomerDAO; import hiber.domain.Room; import java.sql.Timestamp; import java.util.List; import javax.servlet.http.HttpServlet; import org.hibernate.Transaction; import com.opensymphony.xwork2.ActionContext; @SuppressWarnings("unused") public class BillUpdateAction { private Integer bid; private Integer id; private Customer customer; private Integer b1; private Integer b2; private List<Customer> customerList =null; private List<Bill> billList =null; public String execute(){ BillDAO dao=new BillDAO(); ?????? ?????? ?????? ?????? ?????? ?????? dao.save(bill); trans.commit(); return "success"; } public Integer getBid() { return bid; } public void setBid(Integer bid) { this.bid = bid; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Customer getCustomer() { return customer; } public void setCustomer(Customer customer) { this.customer = customer; } public Integer getB1() { return b1; } public void setB1(Integer b1) { this.b1 = b1; } public Integer getB2() { return b2; } public void setB2(Integer b2) { this.b2 = b2; } public List<Customer> getCustomerList() { return customerList; } public void setCustomerList(List<Customer> customerList) { this.customerList = customerList; } public List<Bill> getBillList() { return billList; } public void setBillList(List<Bill> billList) { this.billList = billList; } } 主要是问号部分不会写,请高手帮我完善。
追问:
不对啊 这样写会报错 麻烦你帮我把整个代码写一下我再试试吧
答案:就加一句:Bill bill = new Bill(id,b1,b2);

sava()方法:public void save(Bill bill) {
  Session session = HibernateSessionFactory.getSession();
  transaction= session.beginTransaction();
  try {
   session.update(bill);
   transaction.commit();
  } catch (HibernateException e) {
   e.printStackTrace();
   if (transaction != null) {
    transaction.rollback();
   }
  } finally {
   transaction = null;
   session.close();
  }
 }

上一个:jsp背景图片如何设置,求代码
下一个:我的JSP网页在page文件夹下面,但是.js文件在JS文件夹下面,调用的时候怎么写代码哦?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,