controller.java.vm 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. package ${packageName}.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 ${packageName}.domain.${ClassName};
  15. import ${packageName}.service.I${ClassName}Service;
  16. import com.ruoyi.common.core.controller.BaseController;
  17. import com.ruoyi.common.core.domain.AjaxResult;
  18. import com.ruoyi.common.utils.poi.ExcelUtil;
  19. #if($table.crud || $table.sub)
  20. import com.ruoyi.common.core.page.TableDataInfo;
  21. #elseif($table.tree)
  22. import com.ruoyi.common.utils.StringUtils;
  23. import com.ruoyi.common.core.domain.Ztree;
  24. #end
  25. /**
  26. * ${functionName}Controller
  27. *
  28. * @author ${author}
  29. * @date ${datetime}
  30. */
  31. @Controller
  32. @RequestMapping("/${moduleName}/${businessName}")
  33. public class ${ClassName}Controller extends BaseController
  34. {
  35. private String prefix = "${moduleName}/${businessName}";
  36. @Autowired
  37. private I${ClassName}Service ${className}Service;
  38. @RequiresPermissions("${permissionPrefix}:view")
  39. @GetMapping()
  40. public String ${businessName}()
  41. {
  42. return prefix + "/${businessName}";
  43. }
  44. #if($table.crud || $table.sub)
  45. /**
  46. * 查询${functionName}列表
  47. */
  48. @RequiresPermissions("${permissionPrefix}:list")
  49. @PostMapping("/list")
  50. @ResponseBody
  51. public TableDataInfo list(${ClassName} ${className})
  52. {
  53. startPage();
  54. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  55. return getDataTable(list);
  56. }
  57. #elseif($table.tree)
  58. /**
  59. * 查询${functionName}树列表
  60. */
  61. @RequiresPermissions("${permissionPrefix}:list")
  62. @PostMapping("/list")
  63. @ResponseBody
  64. public List<${ClassName}> list(${ClassName} ${className})
  65. {
  66. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  67. return list;
  68. }
  69. #end
  70. /**
  71. * 导出${functionName}列表
  72. */
  73. @RequiresPermissions("${permissionPrefix}:export")
  74. @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
  75. @PostMapping("/export")
  76. @ResponseBody
  77. public AjaxResult export(${ClassName} ${className})
  78. {
  79. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  80. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
  81. return util.exportExcel(list, "${functionName}数据");
  82. }
  83. #if($table.crud || $table.sub)
  84. /**
  85. * 新增${functionName}
  86. */
  87. @GetMapping("/add")
  88. public String add()
  89. {
  90. return prefix + "/add";
  91. }
  92. #elseif($table.tree)
  93. /**
  94. * 新增${functionName}
  95. */
  96. @GetMapping(value = { "/add/{${pkColumn.javaField}}", "/add/" })
  97. public String add(@PathVariable(value = "${pkColumn.javaField}", required = false) Long ${pkColumn.javaField}, ModelMap mmap)
  98. {
  99. if (StringUtils.isNotNull(${pkColumn.javaField}))
  100. {
  101. mmap.put("${className}", ${className}Service.select${ClassName}ById(${pkColumn.javaField}));
  102. }
  103. return prefix + "/add";
  104. }
  105. #end
  106. /**
  107. * 新增保存${functionName}
  108. */
  109. @RequiresPermissions("${permissionPrefix}:add")
  110. @Log(title = "${functionName}", businessType = BusinessType.INSERT)
  111. @PostMapping("/add")
  112. @ResponseBody
  113. public AjaxResult addSave(${ClassName} ${className})
  114. {
  115. return toAjax(${className}Service.insert${ClassName}(${className}));
  116. }
  117. /**
  118. * 修改${functionName}
  119. */
  120. @GetMapping("/edit/{${pkColumn.javaField}}")
  121. public String edit(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}, ModelMap mmap)
  122. {
  123. ${ClassName} ${className} = ${className}Service.select${ClassName}ById(${pkColumn.javaField});
  124. mmap.put("${className}", ${className});
  125. return prefix + "/edit";
  126. }
  127. /**
  128. * 修改保存${functionName}
  129. */
  130. @RequiresPermissions("${permissionPrefix}:edit")
  131. @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
  132. @PostMapping("/edit")
  133. @ResponseBody
  134. public AjaxResult editSave(${ClassName} ${className})
  135. {
  136. return toAjax(${className}Service.update${ClassName}(${className}));
  137. }
  138. #if($table.crud || $table.sub)
  139. /**
  140. * 删除${functionName}
  141. */
  142. @RequiresPermissions("${permissionPrefix}:remove")
  143. @Log(title = "${functionName}", businessType = BusinessType.DELETE)
  144. @PostMapping( "/remove")
  145. @ResponseBody
  146. public AjaxResult remove(String ids)
  147. {
  148. return toAjax(${className}Service.delete${ClassName}ByIds(ids));
  149. }
  150. #elseif($table.tree)
  151. /**
  152. * 删除
  153. */
  154. @RequiresPermissions("${permissionPrefix}:remove")
  155. @Log(title = "${functionName}", businessType = BusinessType.DELETE)
  156. @GetMapping("/remove/{${pkColumn.javaField}}")
  157. @ResponseBody
  158. public AjaxResult remove(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
  159. {
  160. return toAjax(${className}Service.delete${ClassName}ById(${pkColumn.javaField}));
  161. }
  162. #end
  163. #if($table.tree)
  164. /**
  165. * 选择${functionName}树
  166. */
  167. #set($BusinessName=$businessName.substring(0,1).toUpperCase() + ${businessName.substring(1)})
  168. @GetMapping(value = { "/select${BusinessName}Tree/{${pkColumn.javaField}}", "/select${BusinessName}Tree/" })
  169. public String select${BusinessName}Tree(@PathVariable(value = "${pkColumn.javaField}", required = false) Long ${pkColumn.javaField}, ModelMap mmap)
  170. {
  171. if (StringUtils.isNotNull(${pkColumn.javaField}))
  172. {
  173. mmap.put("${className}", ${className}Service.select${ClassName}ById(${pkColumn.javaField}));
  174. }
  175. return prefix + "/tree";
  176. }
  177. /**
  178. * 加载${functionName}树列表
  179. */
  180. @GetMapping("/treeData")
  181. @ResponseBody
  182. public List<Ztree> treeData()
  183. {
  184. List<Ztree> ztrees = ${className}Service.select${ClassName}Tree();
  185. return ztrees;
  186. }
  187. #end
  188. }