Controller.java.vm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package ${package}.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.framework.aspectj.lang.annotation.Log;
  13. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  14. import ${package}.domain.${className};
  15. import ${package}.service.I${className}Service;
  16. import com.ruoyi.framework.web.controller.BaseController;
  17. import com.ruoyi.framework.web.page.TableDataInfo;
  18. import com.ruoyi.framework.web.domain.AjaxResult;
  19. import com.ruoyi.common.utils.poi.ExcelUtil;
  20. /**
  21. * ${tableComment}信息操作处理
  22. *
  23. * @author ${author}
  24. * @date ${datetime}
  25. */
  26. @Controller
  27. @RequestMapping("/${moduleName}/${classname}")
  28. public class ${className}Controller extends BaseController
  29. {
  30. private String prefix = "${moduleName}/${classname}";
  31. @Autowired
  32. private I${className}Service ${classname}Service;
  33. @RequiresPermissions("${moduleName}:${classname}:view")
  34. @GetMapping()
  35. public String ${classname}()
  36. {
  37. return prefix + "/${classname}";
  38. }
  39. /**
  40. * 查询${tableComment}列表
  41. */
  42. @RequiresPermissions("${moduleName}:${classname}:list")
  43. @PostMapping("/list")
  44. @ResponseBody
  45. public TableDataInfo list(${className} ${classname})
  46. {
  47. startPage();
  48. List<${className}> list = ${classname}Service.select${className}List(${classname});
  49. return getDataTable(list);
  50. }
  51. /**
  52. * 导出${tableComment}列表
  53. */
  54. @RequiresPermissions("${moduleName}:${classname}:export")
  55. @PostMapping("/export")
  56. @ResponseBody
  57. public AjaxResult export(${className} ${classname})
  58. {
  59. List<${className}> list = ${classname}Service.select${className}List(${classname});
  60. ExcelUtil<${className}> util = new ExcelUtil<${className}>(${className}.class);
  61. return util.exportExcel(list, "${classname}");
  62. }
  63. /**
  64. * 新增${tableComment}
  65. */
  66. @GetMapping("/add")
  67. public String add()
  68. {
  69. return prefix + "/add";
  70. }
  71. /**
  72. * 新增保存${tableComment}
  73. */
  74. @RequiresPermissions("${moduleName}:${classname}:add")
  75. @Log(title = "${tableComment}", businessType = BusinessType.INSERT)
  76. @PostMapping("/add")
  77. @ResponseBody
  78. public AjaxResult addSave(${className} ${classname})
  79. {
  80. return toAjax(${classname}Service.insert${className}(${classname}));
  81. }
  82. /**
  83. * 修改${tableComment}
  84. */
  85. @GetMapping("/edit/{${primaryKey.attrname}}")
  86. public String edit(@PathVariable("${primaryKey.attrname}") ${primaryKey.attrType} ${primaryKey.attrname}, ModelMap mmap)
  87. {
  88. ${className} ${classname} = ${classname}Service.select${className}ById(${primaryKey.attrname});
  89. mmap.put("${classname}", ${classname});
  90. return prefix + "/edit";
  91. }
  92. /**
  93. * 修改保存${tableComment}
  94. */
  95. @RequiresPermissions("${moduleName}:${classname}:edit")
  96. @Log(title = "${tableComment}", businessType = BusinessType.UPDATE)
  97. @PostMapping("/edit")
  98. @ResponseBody
  99. public AjaxResult editSave(${className} ${classname})
  100. {
  101. return toAjax(${classname}Service.update${className}(${classname}));
  102. }
  103. /**
  104. * 删除${tableComment}
  105. */
  106. @RequiresPermissions("${moduleName}:${classname}:remove")
  107. @Log(title = "${tableComment}", businessType = BusinessType.DELETE)
  108. @PostMapping( "/remove")
  109. @ResponseBody
  110. public AjaxResult remove(String ids)
  111. {
  112. return toAjax(${classname}Service.delete${className}ByIds(ids));
  113. }
  114. }