Controller.java.vm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package ${package}.web.controller;
  2. import java.util.List;
  3. import org.apache.shiro.authz.annotation.RequiresPermissions;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.ui.ModelMap;
  7. import org.springframework.web.bind.annotation.GetMapping;
  8. import org.springframework.web.bind.annotation.PathVariable;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.ResponseBody;
  12. import com.ruoyi.common.annotation.Log;
  13. import com.ruoyi.common.enums.BusinessType;
  14. import ${package}.domain.${className};
  15. import ${package}.service.I${className}Service;
  16. import com.ruoyi.framework.web.base.BaseController;
  17. import com.ruoyi.framework.web.page.TableDataInfo;
  18. import com.ruoyi.common.base.AjaxResult;
  19. /**
  20. * ${tableComment} 信息操作处理
  21. *
  22. * @author ${author}
  23. * @date ${datetime}
  24. */
  25. @Controller
  26. @RequestMapping("/${moduleName}/${classname}")
  27. public class ${className}Controller extends BaseController
  28. {
  29. private String prefix = "${moduleName}/${classname}";
  30. @Autowired
  31. private I${className}Service ${classname}Service;
  32. @RequiresPermissions("${moduleName}:${classname}:view")
  33. @GetMapping()
  34. public String ${classname}()
  35. {
  36. return prefix + "/${classname}";
  37. }
  38. /**
  39. * 查询${tableComment}列表
  40. */
  41. @RequiresPermissions("${moduleName}:${classname}:list")
  42. @PostMapping("/list")
  43. @ResponseBody
  44. public TableDataInfo list(${className} ${classname})
  45. {
  46. startPage();
  47. List<${className}> list = ${classname}Service.select${className}List(${classname});
  48. return getDataTable(list);
  49. }
  50. /**
  51. * 新增${tableComment}
  52. */
  53. @GetMapping("/add")
  54. public String add()
  55. {
  56. return prefix + "/add";
  57. }
  58. /**
  59. * 新增保存${tableComment}
  60. */
  61. @RequiresPermissions("${moduleName}:${classname}:add")
  62. @Log(title = "${tableComment}", businessType = BusinessType.INSERT)
  63. @PostMapping("/add")
  64. @ResponseBody
  65. public AjaxResult addSave(${className} ${classname})
  66. {
  67. return toAjax(${classname}Service.insert${className}(${classname}));
  68. }
  69. /**
  70. * 修改${tableComment}
  71. */
  72. @GetMapping("/edit/{${primaryKey.attrname}}")
  73. public String edit(@PathVariable("${primaryKey.attrname}") ${primaryKey.attrType} ${primaryKey.attrname}, ModelMap mmap)
  74. {
  75. ${className} ${classname} = ${classname}Service.select${className}ById(${primaryKey.attrname});
  76. mmap.put("${classname}", ${classname});
  77. return prefix + "/edit";
  78. }
  79. /**
  80. * 修改保存${tableComment}
  81. */
  82. @RequiresPermissions("${moduleName}:${classname}:edit")
  83. @Log(title = "${tableComment}", businessType = BusinessType.UPDATE)
  84. @PostMapping("/edit")
  85. @ResponseBody
  86. public AjaxResult editSave(${className} ${classname})
  87. {
  88. return toAjax(${classname}Service.update${className}(${classname}));
  89. }
  90. /**
  91. * 删除${tableComment}
  92. */
  93. @RequiresPermissions("${moduleName}:${classname}:remove")
  94. @Log(title = "${tableComment}", businessType = BusinessType.DELETE)
  95. @PostMapping( "/remove")
  96. @ResponseBody
  97. public AjaxResult remove(String ids)
  98. {
  99. return toAjax(${classname}Service.delete${className}ByIds(ids));
  100. }
  101. }