MenuAction.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.Menu;
  8. import com.post.service.MenuServiceI;
  9. /**
  10. * 菜单
  11. */
  12. @Action(value = "menuAction", results = { @Result(name = "menuManager", location = "/admin/menu/menuManager.jsp"), @Result(name = "menuAdd", location = "/admin/menu/menuAdd.jsp"), @Result(name = "menuEdit", location = "/admin/menu/menuEdit.jsp") })
  13. public class MenuAction extends BaseAction implements ModelDriven<Menu> {
  14. private MenuServiceI menuService;
  15. public MenuServiceI getMenuService() {
  16. return menuService;
  17. }
  18. @Autowired
  19. public void setMenuService(MenuServiceI menuService) {
  20. this.menuService = menuService;
  21. }
  22. private Menu menu = new Menu();
  23. public Menu getModel() {
  24. return menu;
  25. }
  26. /**
  27. * 首页获得菜单树
  28. */
  29. public void do_tree() {
  30. super.writeJson(menuService.tree(menu, false));
  31. }
  32. public void do_treeRecursive() {
  33. super.writeJson(menuService.tree(menu, true));
  34. }
  35. public String menuManager() {
  36. return "menuManager";
  37. }
  38. /**
  39. * 获得菜单treegrid
  40. */
  41. public void do_treegrid() {
  42. super.writeJson(menuService.tgrid(menu, true));
  43. //super.writeJson(menuService.treegrid(menu));
  44. }
  45. /**
  46. * 删除一个菜单
  47. */
  48. public void delete() {
  49. Json j = new Json();
  50. try {
  51. menuService.delete(menu);
  52. j.setSuccess(true);
  53. j.setMsg("删除成功!");
  54. j.setObj(menu.getCid());
  55. } catch (Exception e) {
  56. j.setMsg("删除失败!");
  57. }
  58. super.writeJson(j);
  59. }
  60. public String menuAdd() {
  61. return "menuAdd";
  62. }
  63. public void add() {
  64. Json j = new Json();
  65. try {
  66. menuService.add(menu);
  67. j.setSuccess(true);
  68. j.setMsg("添加成功!");
  69. } catch (Exception e) {
  70. j.setMsg("添加失败!");
  71. }
  72. super.writeJson(j);
  73. }
  74. public String menuEdit() {
  75. return "menuEdit";
  76. }
  77. /**
  78. * 编辑菜单
  79. */
  80. public void edit() {
  81. Json j = new Json();
  82. try {
  83. menuService.edit(menu);
  84. j.setSuccess(true);
  85. j.setMsg("编辑成功!");
  86. } catch (Exception e) {
  87. j.setMsg("编辑失败!");
  88. }
  89. writeJson(j);
  90. }
  91. public void do_UserMenus(){
  92. super.writeJson(menuService.getUserMenus(menu));
  93. }
  94. }