RuoYi-Cloud/ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm

117 lines
4.2 KiB
Plaintext
Raw Normal View History

2020-05-24 20:40:55 +08:00
package ${packageName}.controller;
import java.util.List;
2020-06-10 11:31:13 +08:00
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
2020-05-24 20:40:55 +08:00
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
2020-06-10 11:31:13 +08:00
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
2020-09-01 13:31:00 +08:00
import com.ruoyi.common.security.annotation.PreAuthorize;
2020-05-24 20:40:55 +08:00
import ${packageName}.domain.${ClassName};
import ${packageName}.service.I${ClassName}Service;
2020-06-10 11:31:13 +08:00
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
2021-01-08 11:08:59 +08:00
#if($table.crud || $table.sub)
2020-06-10 11:31:13 +08:00
import com.ruoyi.common.core.web.page.TableDataInfo;
2020-05-24 20:40:55 +08:00
#elseif($table.tree)
#end
/**
* ${functionName}Controller
*
* @author ${author}
* @date ${datetime}
*/
@RestController
2020-06-10 11:31:13 +08:00
@RequestMapping("/${businessName}")
2020-05-24 20:40:55 +08:00
public class ${ClassName}Controller extends BaseController
{
@Autowired
private I${ClassName}Service ${className}Service;
/**
* 查询${functionName}列表
*/
2020-09-01 13:31:00 +08:00
@PreAuthorize(hasPermi = "${permissionPrefix}:list")
2020-05-24 20:40:55 +08:00
@GetMapping("/list")
2021-01-08 11:08:59 +08:00
#if($table.crud || $table.sub)
2020-05-24 20:40:55 +08:00
public TableDataInfo list(${ClassName} ${className})
{
startPage();
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return getDataTable(list);
}
#elseif($table.tree)
public AjaxResult list(${ClassName} ${className})
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
return AjaxResult.success(list);
}
#end
/**
* 导出${functionName}列表
*/
2020-09-01 13:31:00 +08:00
@PreAuthorize(hasPermi = "${permissionPrefix}:export")
2020-05-24 20:40:55 +08:00
@Log(title = "${functionName}", businessType = BusinessType.EXPORT)
2020-06-14 15:30:58 +08:00
@PostMapping("/export")
2020-06-10 11:31:13 +08:00
public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException
2020-05-24 20:40:55 +08:00
{
List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);
2021-04-13 14:54:54 +08:00
util.exportExcel(response, list, "${functionName}数据");
2020-05-24 20:40:55 +08:00
}
/**
* 获取${functionName}详细信息
*/
2020-09-01 13:31:00 +08:00
@PreAuthorize(hasPermi = "${permissionPrefix}:query")
2020-05-24 20:40:55 +08:00
@GetMapping(value = "/{${pkColumn.javaField}}")
public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField})
{
2021-07-30 22:33:09 +08:00
return AjaxResult.success(${className}Service.select${ClassName}By${pkColumn.capJavaField}(${pkColumn.javaField}));
2020-05-24 20:40:55 +08:00
}
/**
* 新增${functionName}
*/
2020-09-01 13:31:00 +08:00
@PreAuthorize(hasPermi = "${permissionPrefix}:add")
2020-05-24 20:40:55 +08:00
@Log(title = "${functionName}", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.insert${ClassName}(${className}));
}
/**
* 修改${functionName}
*/
2020-09-01 13:31:00 +08:00
@PreAuthorize(hasPermi = "${permissionPrefix}:edit")
2020-05-24 20:40:55 +08:00
@Log(title = "${functionName}", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody ${ClassName} ${className})
{
return toAjax(${className}Service.update${ClassName}(${className}));
}
/**
* 删除${functionName}
*/
2020-09-01 13:31:00 +08:00
@PreAuthorize(hasPermi = "${permissionPrefix}:remove")
2020-05-24 20:40:55 +08:00
@Log(title = "${functionName}", businessType = BusinessType.DELETE)
@DeleteMapping("/{${pkColumn.javaField}s}")
public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s)
{
2021-07-30 22:33:09 +08:00
return toAjax(${className}Service.delete${ClassName}By${pkColumn.capJavaField}s(${pkColumn.javaField}s));
2020-05-24 20:40:55 +08:00
}
}