templates.controller.vm Maven / Gradle / Ivy
package $!{package.Controller};
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import com.github.zj.dreamly.tool.util.PageQuery;
import com.github.zj.dreamly.swagger.constant.DataType;
import com.github.zj.dreamly.swagger.constant.ParamType;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import $!{package.Entity}.$!{entity};
import $!{package.Service}.$!{table.serviceName};
#if($!{superControllerClassPackage})
import $!{superControllerClassPackage};
#end
#if(!$!{superEntityClass})
#end
/**
* $!{table.comment} 控制器
*
* @author $!{author}
* @since $!{date}
*/
@RestController
@AllArgsConstructor
@RequestMapping("/$!{table.name}s")
@Api(value = "$!{table.comment}", tags = "$!{table.comment}接口")
@Validated
#if($!{superControllerClass})
public class $!{table.controllerName} extends $!{superControllerClass} {
#else
public class $!{table.controllerName} {
#end
private final $!{table.serviceName} $!{table.entityPath}Service;
/**
* 获取$!{table.comment}详情
*/
@GetMapping("/{id}")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "获取$!{table.comment}详情数据", notes = "传入主键id")
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "传入主键id", dataType = DataType.STRING, paramType = ParamType.PATH)})
public ResponseEntity<$!{entity}> detail(@PathVariable("id") String id) {
return ResponseEntity.data($!{table.entityPath}Service.get$!{entity}ById(Long.valueOf(id)));
}
/**
* 获取$!{table.comment}列表
*/
@GetMapping("/page")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "获取$!{table.comment}列表", notes = "传入page")
@ApiImplicitParams({
@ApiImplicitParam(value = "当前页", name = "current", dataType = DataType.LONG, paramType = ParamType.QUERY),
@ApiImplicitParam(value = "页面大小", name = "size", dataType = DataType.LONG, paramType = ParamType.QUERY)
})
public ResponseEntity> page(@Valid PageQuery query) {
return ResponseEntity.data($!{table.entityPath}Service.get$!{entity}Page(query));
}
/**
* 新增$!{table.comment}
*/
@PostMapping
@ApiOperationSupport(order = 3, ignoreParameters = {
"$!{table.entityPath}.createTime",
"$!{table.entityPath}.updateTime",
"$!{table.entityPath}.id"
})
@ApiOperation(value = "新增$!{table.comment}", notes = "传入$!{table.entityPath}")
public ResponseEntity save(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
$!{table.entityPath}Service.save$!{entity}($!{table.entityPath});
return ResponseEntity.success("新增成功");
}
/**
* 修改$!{table.comment}
*/
@PutMapping
@ApiOperationSupport(order = 4, ignoreParameters = {
"$!{table.entityPath}.createTime",
"$!{table.entityPath}.updateTime"
})
@ApiOperation(value = "修改$!{table.comment}", notes = "传入$!{table.entityPath}")
public ResponseEntity update(@Valid @RequestBody $!{entity} $!{table.entityPath}) {
$!{table.entityPath}Service.update$!{entity}ById($!{table.entityPath});
return ResponseEntity.success("修改成功");
}
/**
* 删除$!{table.comment}
*/
@DeleteMapping("/{id}")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "删除$!{table.comment}", notes = "传入主键id")
public ResponseEntity remove(@PathVariable("id") String id) {
$!{table.entityPath}Service.remove$!{entity}ById(Long.valueOf(id));
return ResponseEntity.success("删除成功");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy