controller.java.vm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package ${packageName}.controller;
  2. import java.util.List;
  3. import java.io.IOException;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.PutMapping;
  9. import org.springframework.web.bind.annotation.DeleteMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import com.ruoyi.common.log.annotation.Log;
  15. import com.ruoyi.common.log.enums.BusinessType;
  16. import com.ruoyi.common.security.annotation.PreAuthorize;
  17. import ${packageName}.domain.${ClassName};
  18. import ${packageName}.service.I${ClassName}Service;
  19. import com.ruoyi.common.core.web.controller.BaseController;
  20. import com.ruoyi.common.core.web.domain.AjaxResult;
  21. import com.ruoyi.common.core.utils.poi.ExcelUtil;
  22. #if($table.crud || $table.sub)
  23. import com.ruoyi.common.core.web.page.TableDataInfo;
  24. #elseif($table.tree)
  25. #end
  26. /**
  27. * ${functionName}Controller
  28. *
  29. * @author ${author}
  30. * @date ${datetime}
  31. */
  32. @RestController
  33. @RequestMapping("/${businessName}")
  34. public class ${ClassName}Controller extends BaseController
  35. {
  36. @Autowired
  37. private I${ClassName}Service ${className}Service;
  38. /**
  39. * 查询${functionName}列表
  40. */
  41. @PreAuthorize(hasPermi = "${permissionPrefix}:list")
  42. @GetMapping("/list")
  43. #if($table.crud || $table.sub)
  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. #elseif($table.tree)
  51. public AjaxResult list(${ClassName} ${className})
  52. {
  53. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  54. return AjaxResult.success(list);
  55. }
  56. #end
  57. /**
  58. * 导出${functionName}列表
  59. */
  60. @PreAuthorize(hasPermi = "${permissionPrefix}:export")
  61. @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
  62. @PostMapping("/export")
  63. public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException
  64. {
  65. List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
  66. ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
  67. util.exportExcel(response, list, "${businessName}");
  68. }
  69. /**
  70. * 获取${functionName}详细信息
  71. */
  72. @PreAuthorize(hasPermi = "${permissionPrefix}:query")
  73. @GetMapping(value = "/{${pkColumn.javaField}}")
  74. public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
  75. {
  76. return AjaxResult.success(${className}Service.select${ClassName}ById(${pkColumn.javaField}));
  77. }
  78. /**
  79. * 新增${functionName}
  80. */
  81. @PreAuthorize(hasPermi = "${permissionPrefix}:add")
  82. @Log(title = "${functionName}", businessType = BusinessType.INSERT)
  83. @PostMapping
  84. public AjaxResult add(@RequestBody ${ClassName} ${className})
  85. {
  86. return toAjax(${className}Service.insert${ClassName}(${className}));
  87. }
  88. /**
  89. * 修改${functionName}
  90. */
  91. @PreAuthorize(hasPermi = "${permissionPrefix}:edit")
  92. @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
  93. @PutMapping
  94. public AjaxResult edit(@RequestBody ${ClassName} ${className})
  95. {
  96. return toAjax(${className}Service.update${ClassName}(${className}));
  97. }
  98. /**
  99. * 删除${functionName}
  100. */
  101. @PreAuthorize(hasPermi = "${permissionPrefix}:remove")
  102. @Log(title = "${functionName}", businessType = BusinessType.DELETE)
  103. @DeleteMapping("/{${pkColumn.javaField}s}")
  104. public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
  105. {
  106. return toAjax(${className}Service.delete${ClassName}ByIds(${pkColumn.javaField}s));
  107. }
  108. }