ProjectAction.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.post.action;
  2. import org.apache.struts2.convention.annotation.Action;
  3. import org.apache.struts2.convention.annotation.Result;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import com.opensymphony.xwork2.ModelDriven;
  6. import com.post.pageModel.Json;
  7. import com.post.pageModel.Project;
  8. import com.post.service.ProjectServiceI;
  9. /**
  10. * 归属项目
  11. */
  12. @Action(value = "projectAction", results = {
  13. @Result(name = "projectManager", location = "/busi/project/projectManager.jsp"),
  14. @Result(name = "projectAdd", location = "/busi/project/projectAdd.jsp"),
  15. @Result(name = "projectEdit", location = "/busi/project/projectEdit.jsp") })
  16. public class ProjectAction extends BaseAction implements ModelDriven<Project> {
  17. private Project project = new Project();
  18. private ProjectServiceI projectService;
  19. public ProjectServiceI getProjectService() {
  20. return projectService;
  21. }
  22. @Autowired
  23. public void setProjectService(ProjectServiceI projectService) {
  24. this.projectService = projectService;
  25. }
  26. @Override
  27. public Project getModel() {
  28. return project;
  29. }
  30. public String projectManager() {
  31. return "projectManager";
  32. }
  33. public String projectAdd() {
  34. return "projectAdd";
  35. }
  36. public String projectEdit() {
  37. return "projectEdit";
  38. }
  39. public void do_datagrid() {
  40. super.writeJson(projectService.datagrid(project));
  41. }
  42. public void add() {
  43. Json j = new Json();
  44. try {
  45. projectService.add(project);
  46. j.setSuccess(true);
  47. j.setMsg("添加成功!");
  48. } catch (Exception e) {
  49. j.setMsg("添加失败!");
  50. }
  51. super.writeJson(j);
  52. }
  53. public void edit() {
  54. Json j = new Json();
  55. try {
  56. projectService.edit(project);
  57. j.setSuccess(true);
  58. j.setMsg("编辑成功!");
  59. } catch (Exception e) {
  60. j.setMsg("编辑失败!");
  61. }
  62. super.writeJson(j);
  63. }
  64. public void delete() {
  65. Json j = new Json();
  66. projectService.delete(project);
  67. j.setSuccess(true);
  68. j.setMsg("删除成功!");
  69. super.writeJson(j);
  70. }
  71. public void do_combobox() {
  72. super.writeJson(projectService.combobox());
  73. }
  74. }