Browse Source

spring-boot-demo-codegen 完成,模板新增 swagger 支持

pull/1/head
Yangkai.Shen 6 years ago
parent
commit
cc98514f31
2 changed files with 28 additions and 12 deletions
  1. +21
    -5
      spring-boot-demo-codegen/src/main/resources/template/Controller.java.vm
  2. +7
    -7
      spring-boot-demo-codegen/src/main/resources/template/Entity.java.vm

+ 21
- 5
spring-boot-demo-codegen/src/main/resources/template/Controller.java.vm View File

@@ -1,14 +1,20 @@
package ${package}.${moduleName}.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
package ${package}import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xkcoding.common.R;
import com.xkcoding.scaffold.log.annotations.ApiLog;
import ${package}.${moduleName}.entity.${className};
import ${package}.${moduleName}.service.${className}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

.${moduleName}.controller;
${package}
.${moduleName}.entity.${className};
${package}
.${moduleName}.service.${className}Service;

/**
* <p>
* ${comments}
@@ -25,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
@RestController
@AllArgsConstructor
@RequestMapping("/${pathName}")
@Api(description = "${className}Controller", tags = {"${comments}"})
public class ${className}Controller {

private final ${className}Service ${classname}Service;
@@ -36,6 +43,8 @@ public class ${className}Controller {
* @return R
*/
@GetMapping("")
@ApiOperation(value = "分页查询${comments}", notes = "分页查询${comments}")
@ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页参数", required = true), @ApiImplicitParam(name = "${classname}", value = "查询条件", required = true)})
public R list${className}(Page page, ${className} ${classname}) {
return new R<>(${classname}Service.page(page,Wrappers.query(${classname})));
}
@@ -47,6 +56,8 @@ public class ${className}Controller {
* @return R
*/
@GetMapping("/{${pk.lowerAttrName}}")
@ApiOperation(value = "通过id查询${comments}", notes = "通过id查询${comments}")
@ApiImplicitParams({@ApiImplicitParam(name = "${pk.lowerAttrName}", value = "主键id", required = true)})
public R get${className}(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.getById(${pk.lowerAttrName}));
}
@@ -58,6 +69,7 @@ public class ${className}Controller {
*/
@ApiLog("新增${comments}")
@PostMapping
@ApiOperation(value = "新增${comments}", notes = "新增${comments}")
public R save${className}(@RequestBody ${className} ${classname}){
return new R<>(${classname}Service.save(${classname}));
}
@@ -70,6 +82,8 @@ public class ${className}Controller {
*/
@ApiLog("修改${comments}")
@PutMapping("/{${pk.lowerAttrName}}")
@ApiOperation(value = "修改${comments}", notes = "修改${comments}")
@ApiImplicitParams({@ApiImplicitParam(name = "${pk.lowerAttrName}", value = "主键id", required = true)})
public R update${className}(@PathVariable ${pk.attrType} ${pk.lowerAttrName}, @RequestBody ${className} ${classname}){
return new R<>(${classname}Service.updateById(${classname}));
}
@@ -81,6 +95,8 @@ public class ${className}Controller {
*/
@ApiLog("删除${comments}")
@DeleteMapping("/{${pk.lowerAttrName}}")
@ApiOperation(value = "删除${comments}", notes = "删除${comments}")
@ApiImplicitParams({@ApiImplicitParam(name = "${pk.lowerAttrName}", value = "主键id", required = true)})
public R delete${className}(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
return new R<>(${classname}Service.removeById(${pk.lowerAttrName}));
}


+ 7
- 7
spring-boot-demo-codegen/src/main/resources/template/Entity.java.vm View File

@@ -1,15 +1,14 @@
package ${package}.${moduleName}.entity;

import com.baomidou.mybatisplus.annotation.TableId;
package ${package}import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

.${moduleName}.entity;
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import java.io.Serializable;
import java.time.LocalDateTime;

/**
* <p>
@@ -25,7 +24,7 @@ import java.time.LocalDateTime;
* @modified: ${author}
*/
@Data
@TableName("${tableName}")
@TableName("${tableName}") @ApiModel(description = "${comments}")
@EqualsAndHashCode(callSuper = true)
public class ${className} extends Model<${className}> {
private static final long serialVersionUID = 1L;
@@ -37,6 +36,7 @@ public class ${className} extends Model<${className}> {
#if($column.columnName == $pk.columnName)
@TableId
#end
@ApiModelProperty(value = "$column.comments")
private $column.attrType $column.lowerAttrName;
#end



Loading…
Cancel
Save