首页>代码>Spring+Struts2+Hibernate+MySQL框架整合开发完整的java WEB增删改查项目入门实例>/HSS/src/com/mstf/action/InfoAction.java
package com.mstf.action;
import java.util.List;
import com.mstf.bean.Info;
import com.mstf.service.InfoService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
@SuppressWarnings("serial")//----------������߾���--
public class InfoAction extends ActionSupport implements ModelDriven<Info>{
//----����ActionSupport���ModelDriven��
private Info info;
private InfoService infoService;
//---����InfoService��
//-------------------дStruts�е���ͼ-----
public String list() throws Exception{
List<Info> infolist=infoService.getAll();
ActionContext.getContext().put("infolist", infolist);
return "list";
}
//-----------������������
public String addUI() throws Exception{
return "addUI";
}
public String add() throws Exception{
infoService.save(info);
return "tolist";
}
//-------������������---��
public String updateUI() throws Exception{
//---��ת����ҳ��
Info infos=infoService.getById(info.getId());
ActionContext.getContext().getValueStack().push(infos);
return "updateUI";
}
public String update() throws Exception{
//---�����IJ���
Info infos=infoService.getById(info.getId());
infos.setName(info.getName());
infos.setAge(info.getAge());
infos.setAddress(info.getAddress());
infoService.update(infos);
return "tolist";
}
public String delete() throws Exception{
infoService.delete(info.getId());
return "tolist";
}
@Override
public Info getModel() {
// TODO Auto-generated method stub
info =new Info();
return info;
}
//------------Ϊprivate InfoService infoService;�ṩgetter��setter������
public InfoService getInfoService() {
return infoService;
}
public void setInfoService(InfoService infoService) {
this.infoService = infoService;
}
}

最近下载
最近浏览
