代码生成器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

142 lines
4.3 KiB

package ${packageName}.${moduleName}.controller;
import ${packageName}.${moduleName}.entity.${entityName};
import ${packageName}.${moduleName}.param.${entityName}Param;
import ${packageName}.${moduleName}.service.${entityName}Service;
import ${packageName}.common.core.web.ApiResult;
import ${packageName}.common.core.web.PageResult;
import ${packageName}.common.core.web.BaseController;
<% if(generateSwagger) { %>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
<% } %>
<% if(generateAuth) { %>
import org.springframework.security.access.prepost.PreAuthorize;
<% } %>
<% if(generateLog) { %>
import ${packageName}.common.core.annotation.OperationLog;
<% } %>
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import java.util.List;
/**
* ${tableComment}控制器
*
* @author ${author}
* @since ${date()}
*/
@Slf4j
<% if(generateSwagger) { %>
@Api(tags = "${tableComment}管理")
<% } %>
@RestController
@RequestMapping("/api/${moduleName}/${entityPath}")
public class ${entityName}Controller extends BaseController {
@Resource
private ${entityName}Service ${entityPath}Service;
<% if(generateSwagger) { %>
@ApiOperation("分页查询${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:list')")
<% } %>
@GetMapping("/page")
public ApiResult<PageResult<${entityName}>> page(${entityName}Param param) {
return success(${entityPath}Service.page(param));
}
<% if(generateSwagger) { %>
@ApiOperation("查询全部${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:list')")
<% } %>
@GetMapping
public ApiResult<List<${entityName}>> list(${entityName}Param param) {
return success(${entityPath}Service.list(param));
}
<% if(generateSwagger) { %>
@ApiOperation("根据ID查询${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:list')")
<% } %>
@GetMapping("/{id}")
public ApiResult<${entityName}> getById(@PathVariable ${primaryKey.propertyType} id) {
return success(${entityPath}Service.getById(id));
}
<% if(generateSwagger) { %>
@ApiOperation("新增${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:save')")
<% } %>
<% if(generateLog) { %>
@OperationLog
<% } %>
@PostMapping
public ApiResult<String> save(@RequestBody ${entityName} ${entityPath}) {
if (${entityPath}Service.save(${entityPath})) {
return success("新增成功");
}
return error("新增失败");
}
<% if(generateSwagger) { %>
@ApiOperation("修改${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:update')")
<% } %>
<% if(generateLog) { %>
@OperationLog
<% } %>
@PutMapping
public ApiResult<String> update(@RequestBody ${entityName} ${entityPath}) {
if (${entityPath}Service.updateById(${entityPath})) {
return success("修改成功");
}
return error("修改失败");
}
<% if(generateSwagger) { %>
@ApiOperation("删除${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:remove')")
<% } %>
<% if(generateLog) { %>
@OperationLog
<% } %>
@DeleteMapping("/{id}")
public ApiResult<String> remove(@PathVariable ${primaryKey.propertyType} id) {
if (${entityPath}Service.removeById(id)) {
return success("删除成功");
}
return error("删除失败");
}
<% if(generateSwagger) { %>
@ApiOperation("批量删除${tableComment}")
<% } %>
<% if(generateAuth) { %>
@PreAuthorize("hasAuthority('${moduleName}:${entityPath}:remove')")
<% } %>
<% if(generateLog) { %>
@OperationLog
<% } %>
@DeleteMapping("/batch")
public ApiResult<String> removeBatch(@RequestBody List<${primaryKey.propertyType}> ids) {
if (${entityPath}Service.removeByIds(ids)) {
return success("批量删除成功");
}
return error("批量删除失败");
}
}