日期:2014-05-17 浏览次数:20743 次
package com.action;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import com.dao.ChanpinxinxiDao;
import com.dao.KehuxinxiDao;
import com.dao.ProducttypeDao;
import com.dao.TypeDao;
import com.entity.Chanpinxinxi;
import com.entity.Kehuxinxi;
import com.entity.Producttype;
import com.entity.Type;
/**
* 修改产品信息
* @author think
*
*/
@Controller
public class ToupdateproductAction {
@Resource ChanpinxinxiDao cpxxdao;
@Resource TypeDao typedao;
@Resource ProducttypeDao protypedao;
@Resource KehuxinxiDao khxxdao;
//input
private int id;
private int pstate;
private int types;
private String pname;
private double price;
private String pspecs;
//output
private boolean ok=false;
public String execute(){
Producttype protype=new Producttype();
Type type=new Type();
Chanpinxinxi cpxx=new Chanpinxinxi();
Kehuxinxi khxx=new Kehuxinxi();
try {
protype=protypedao.findById(types);
type=typedao.findById(pstate);
khxx=khxxdao.findById(1);
cpxx=cpxxdao.findById(id);
cpxx.setChanpinmingcheng(pname);
cpxx.setProducttype(protype);
cpxx.setType(type);
cpxx.setJiage(price);
cpxx.setGuige(pspecs);
cpxx.setKehuxinxi(khxx);
cpxxdao.updateCPXX(cpxx);
ok=true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
ok=false;
}
return "success";
}
public int getPstate() {
return pstate;
}
public void setPstate(int pstate) {
this.pstate = pstate;
}
public int getTypes() {
return types;
}
public void setTypes(int types) {
this.types = types;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getPspecs() {
return pspecs;
}
public void setPspecs(String pspecs) {
this.pspecs = pspecs;
}
public boolean isOk() {
return ok;
}
public void setOk(boolean ok) {
this.ok = ok;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
package com.dao.impl;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotat