当前位置 : 主页 > 编程语言 > java >

Struts2---Action类继承ActionSupport并实现模型驱动

来源:互联网 收集:自由互联 发布时间:2021-06-28
gistfile1.txt public class DepartmentAction extends ActionSupport implements ModelDriven {//模型驱动需要使用的对象private Department department = new Department();public Department getModel() {return department;}//Spring注入部门
gistfile1.txt
public class DepartmentAction extends ActionSupport implements ModelDriven
 
  {
	
	//模型驱动需要使用的对象
	private Department department = new Department();
	
	public Department getModel() {
		return department;
	}
	
	//Spring注入部门管理的Service
	private DepartmentService DepartmentService;
	
	public void setDepartmentService(DepartmentService DepartmentService) {
		this.DepartmentService = DepartmentService;
	}
	
	//通过action返回添加的视图的jsp
	public String saveUI(){
		return "saveUI";
	}
	
	//添加部门的save方法
	public String saveInfo(){
		DepartmentService.save(department);
		return "saveSuccess";
	}

	public String delete(){
		Department dep = DepartmentService.editById(department.getDid());
		DepartmentService.delete(dep);
		return "deleteSuccess";
	}
	
}
 
上一篇:StaticClass
下一篇:java NIO学习
网友评论