Skip to content

Commit cc98514

Browse files
committed
✨ spring-boot-demo-codegen 完成,模板新增 swagger 支持
1 parent ecfac23 commit cc98514

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

spring-boot-demo-codegen/src/main/resources/template/Controller.java.vm

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
package ${package}.${moduleName}.controller;
2-
3-
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
1+
package ${package}import com.baomidou.mybatisplus.core.toolkit.Wrappers;
42
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
53
import com.xkcoding.common.R;
64
import com.xkcoding.scaffold.log.annotations.ApiLog;
7-
import ${package}.${moduleName}.entity.${className};
8-
import ${package}.${moduleName}.service.${className}Service;
5+
import io.swagger.annotations.Api;
6+
import io.swagger.annotations.ApiImplicitParam;
7+
import io.swagger.annotations.ApiImplicitParams;
8+
import io.swagger.annotations.ApiOperation;
99
import lombok.AllArgsConstructor;
1010
import org.springframework.web.bind.annotation.*;
1111

12+
.${moduleName}.controller;
13+
${package}
14+
.${moduleName}.entity.${className};
15+
${package}
16+
.${moduleName}.service.${className}Service;
17+
1218
/**
1319
* <p>
1420
* ${comments}
@@ -25,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
2531
@RestController
2632
@AllArgsConstructor
2733
@RequestMapping("/${pathName}")
34+
@Api(description = "${className}Controller", tags = {"${comments}"})
2835
public class ${className}Controller {
2936

3037
private final ${className}Service ${classname}Service;
@@ -36,6 +43,8 @@ public class ${className}Controller {
3643
* @return R
3744
*/
3845
@GetMapping("")
46+
@ApiOperation(value = "分页查询${comments}", notes = "分页查询${comments}")
47+
@ApiImplicitParams({@ApiImplicitParam(name = "page", value = "分页参数", required = true), @ApiImplicitParam(name = "${classname}", value = "查询条件", required = true)})
3948
public R list${className}(Page page, ${className} ${classname}) {
4049
return new R<>(${classname}Service.page(page,Wrappers.query(${classname})));
4150
}
@@ -47,6 +56,8 @@ public class ${className}Controller {
4756
* @return R
4857
*/
4958
@GetMapping("/{${pk.lowerAttrName}}")
59+
@ApiOperation(value = "通过id查询${comments}", notes = "通过id查询${comments}")
60+
@ApiImplicitParams({@ApiImplicitParam(name = "${pk.lowerAttrName}", value = "主键id", required = true)})
5061
public R get${className}(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
5162
return new R<>(${classname}Service.getById(${pk.lowerAttrName}));
5263
}
@@ -58,6 +69,7 @@ public class ${className}Controller {
5869
*/
5970
@ApiLog("新增${comments}")
6071
@PostMapping
72+
@ApiOperation(value = "新增${comments}", notes = "新增${comments}")
6173
public R save${className}(@RequestBody ${className} ${classname}){
6274
return new R<>(${classname}Service.save(${classname}));
6375
}
@@ -70,6 +82,8 @@ public class ${className}Controller {
7082
*/
7183
@ApiLog("修改${comments}")
7284
@PutMapping("/{${pk.lowerAttrName}}")
85+
@ApiOperation(value = "修改${comments}", notes = "修改${comments}")
86+
@ApiImplicitParams({@ApiImplicitParam(name = "${pk.lowerAttrName}", value = "主键id", required = true)})
7387
public R update${className}(@PathVariable ${pk.attrType} ${pk.lowerAttrName}, @RequestBody ${className} ${classname}){
7488
return new R<>(${classname}Service.updateById(${classname}));
7589
}
@@ -81,6 +95,8 @@ public class ${className}Controller {
8195
*/
8296
@ApiLog("删除${comments}")
8397
@DeleteMapping("/{${pk.lowerAttrName}}")
98+
@ApiOperation(value = "删除${comments}", notes = "删除${comments}")
99+
@ApiImplicitParams({@ApiImplicitParam(name = "${pk.lowerAttrName}", value = "主键id", required = true)})
84100
public R delete${className}(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
85101
return new R<>(${classname}Service.removeById(${pk.lowerAttrName}));
86102
}

spring-boot-demo-codegen/src/main/resources/template/Entity.java.vm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
package ${package}.${moduleName}.entity;
2-
3-
import com.baomidou.mybatisplus.annotation.TableId;
1+
package ${package}import com.baomidou.mybatisplus.annotation.TableId;
42
import com.baomidou.mybatisplus.annotation.TableName;
53
import com.baomidou.mybatisplus.extension.activerecord.Model;
4+
import io.swagger.annotations.ApiModel;
5+
import io.swagger.annotations.ApiModelProperty;
66
import lombok.Data;
77
import lombok.EqualsAndHashCode;
8+
9+
.${moduleName}.entity;
810
#if(${hasBigDecimal})
9-
import java.math.BigDecimal;
1011
#end
11-
import java.io.Serializable;
12-
import java.time.LocalDateTime;
1312

1413
/**
1514
* <p>
@@ -25,7 +24,7 @@ import java.time.LocalDateTime;
2524
* @modified: ${author}
2625
*/
2726
@Data
28-
@TableName("${tableName}")
27+
@TableName("${tableName}") @ApiModel(description = "${comments}")
2928
@EqualsAndHashCode(callSuper = true)
3029
public class ${className} extends Model<${className}> {
3130
private static final long serialVersionUID = 1L;
@@ -37,6 +36,7 @@ public class ${className} extends Model<${className}> {
3736
#if($column.columnName == $pk.columnName)
3837
@TableId
3938
#end
39+
@ApiModelProperty(value = "$column.comments")
4040
private $column.attrType $column.lowerAttrName;
4141
#end
4242

0 commit comments

Comments
 (0)