123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- package ${packageName}.controller;
- import java.util.List;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.ModelMap;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.enums.BusinessType;
- import ${packageName}.domain.${ClassName};
- import ${packageName}.service.I${ClassName}Service;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.utils.poi.ExcelUtil;
- #if($table.crud || $table.sub)
- import com.ruoyi.common.core.page.TableDataInfo;
- #elseif($table.tree)
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.core.domain.Ztree;
- #end
- /**
- * ${functionName}Controller
- *
- * @author ${author}
- * @date ${datetime}
- */
- @Controller
- @RequestMapping("/${moduleName}/${businessName}")
- public class ${ClassName}Controller extends BaseController
- {
- private String prefix = "${moduleName}/${businessName}";
- @Autowired
- private I${ClassName}Service ${className}Service;
- @RequiresPermissions("${permissionPrefix}:view")
- @GetMapping()
- public String ${businessName}()
- {
- return prefix + "/${businessName}";
- }
- #if($table.crud || $table.sub)
- /**
- * 查询${functionName}列表
- */
- @RequiresPermissions("${permissionPrefix}:list")
- @PostMapping("/list")
- @ResponseBody
- public TableDataInfo list(${ClassName} ${className})
- {
- startPage();
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- return getDataTable(list);
- }
- #elseif($table.tree)
- /**
- * 查询${functionName}树列表
- */
- @RequiresPermissions("${permissionPrefix}:list")
- @PostMapping("/list")
- @ResponseBody
- public List<${ClassName}> list(${ClassName} ${className})
- {
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- return list;
- }
- #end
- /**
- * 导出${functionName}列表
- */
- @RequiresPermissions("${permissionPrefix}:export")
- @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
- @PostMapping("/export")
- @ResponseBody
- public AjaxResult export(${ClassName} ${className})
- {
- List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
- ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
- return util.exportExcel(list, "${functionName}数据");
- }
- #if($table.crud || $table.sub)
- /**
- * 新增${functionName}
- */
- @GetMapping("/add")
- public String add()
- {
- return prefix + "/add";
- }
- #elseif($table.tree)
- /**
- * 新增${functionName}
- */
- @GetMapping(value = { "/add/{${pkColumn.javaField}}", "/add/" })
- public String add(@PathVariable(value = "${pkColumn.javaField}", required = false) Long ${pkColumn.javaField}, ModelMap mmap)
- {
- if (StringUtils.isNotNull(${pkColumn.javaField}))
- {
- mmap.put("${className}", ${className}Service.select${ClassName}ById(${pkColumn.javaField}));
- }
- return prefix + "/add";
- }
- #end
- /**
- * 新增保存${functionName}
- */
- @RequiresPermissions("${permissionPrefix}:add")
- @Log(title = "${functionName}", businessType = BusinessType.INSERT)
- @PostMapping("/add")
- @ResponseBody
- public AjaxResult addSave(${ClassName} ${className})
- {
- return toAjax(${className}Service.insert${ClassName}(${className}));
- }
- /**
- * 修改${functionName}
- */
- @GetMapping("/edit/{${pkColumn.javaField}}")
- public String edit(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}, ModelMap mmap)
- {
- ${ClassName} ${className} = ${className}Service.select${ClassName}ById(${pkColumn.javaField});
- mmap.put("${className}", ${className});
- return prefix + "/edit";
- }
- /**
- * 修改保存${functionName}
- */
- @RequiresPermissions("${permissionPrefix}:edit")
- @Log(title = "${functionName}", businessType = BusinessType.UPDATE)
- @PostMapping("/edit")
- @ResponseBody
- public AjaxResult editSave(${ClassName} ${className})
- {
- return toAjax(${className}Service.update${ClassName}(${className}));
- }
- #if($table.crud || $table.sub)
- /**
- * 删除${functionName}
- */
- @RequiresPermissions("${permissionPrefix}:remove")
- @Log(title = "${functionName}", businessType = BusinessType.DELETE)
- @PostMapping( "/remove")
- @ResponseBody
- public AjaxResult remove(String ids)
- {
- return toAjax(${className}Service.delete${ClassName}ByIds(ids));
- }
- #elseif($table.tree)
- /**
- * 删除
- */
- @RequiresPermissions("${permissionPrefix}:remove")
- @Log(title = "${functionName}", businessType = BusinessType.DELETE)
- @GetMapping("/remove/{${pkColumn.javaField}}")
- @ResponseBody
- public AjaxResult remove(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
- {
- return toAjax(${className}Service.delete${ClassName}ById(${pkColumn.javaField}));
- }
- #end
- #if($table.tree)
- /**
- * 选择${functionName}树
- */
- #set($BusinessName=$businessName.substring(0,1).toUpperCase() + ${businessName.substring(1)})
- @GetMapping(value = { "/select${BusinessName}Tree/{${pkColumn.javaField}}", "/select${BusinessName}Tree/" })
- public String select${BusinessName}Tree(@PathVariable(value = "${pkColumn.javaField}", required = false) Long ${pkColumn.javaField}, ModelMap mmap)
- {
- if (StringUtils.isNotNull(${pkColumn.javaField}))
- {
- mmap.put("${className}", ${className}Service.select${ClassName}ById(${pkColumn.javaField}));
- }
- return prefix + "/tree";
- }
- /**
- * 加载${functionName}树列表
- */
- @GetMapping("/treeData")
- @ResponseBody
- public List<Ztree> treeData()
- {
- List<Ztree> ztrees = ${className}Service.select${ClassName}Tree();
- return ztrees;
- }
- #end
- }
|