首页>代码>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{ //---进行修改操作 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; } }