MyBatis Plus Generator——基于Velocity的Controller参考模板(集成MyBatis Plus、Swagger2、自封装Response、分页)
生活随笔
收集整理的這篇文章主要介紹了
MyBatis Plus Generator——基于Velocity的Controller参考模板(集成MyBatis Plus、Swagger2、自封装Response、分页)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼生成器
MyBatis Plus Generator——MyBatis Plus代碼生成器DEMO
解決方案
包含:MyBatis Plus、Swagger2、自封裝Response、MyBatis Plus分頁插件、主鍵類型判斷
package ${package.Controller};import com.hailiu.web.bean.ResponseBean; import ${package.Entity}.${entity}; import ${package.Service}.${table.serviceName};import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; 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.RequestMethod; #if(${restControllerStyle}) import org.springframework.web.bind.annotation.RestController; #else import org.springframework.stereotype.Controller; #end #if(${superControllerClassPackage}) import ${superControllerClassPackage}; #end import static com.hailiu.web.common.Constants.PAGE_LIMIT; import static com.hailiu.web.common.Constants.DEFAULT_PAGE_NUM;/*** $!{table.comment} 前端控制器** @author ${author}* @version 1.0.0* @date ${date} ${cfg.time}*/ #if(${restControllerStyle}) @RestController #else @Controller #end @RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end") @Api(tags = "${entity}前端控制器") #if(${kotlin}) class ${table.controllerName}#if(${superControllerClass}) : ${superControllerClass}()#end#else #if(${superControllerClass}) public class ${table.controllerName} extends ${superControllerClass} { #else public class ${table.controllerName} { #endprivate final ${table.serviceName} i${entity}Service;public ${table.controllerName}(${table.serviceName} i${entity}Service) {this.i${entity}Service = i${entity}Service;}/*** $!{table.comment}列表* @return ResponseBean*/@ApiOperation(value = "獲取所有$!{table.comment}",notes = "獲取所有$!{table.comment}")@RequestMapping(value = "/list",method = {RequestMethod.GET})public ResponseBean list(){return ResponseBean.success(i${entity}Service.list());}/*** $!{table.comment}分頁* @return ResponseBean*/@ApiOperation(value = "$!{table.comment}分頁查詢",notes = "$!{table.comment}分頁查詢")@ResponseBody@RequestMapping(value = "/page",method = {RequestMethod.GET})public ResponseBean page(@ApiParam(name = "page",value = "頁數")@RequestParam(defaultValue = DEFAULT_PAGE_NUM) Integer page,@ApiParam(name = "size",value = "記錄數")@RequestParam(defaultValue = PAGE_LIMIT) Integer size){return ResponseBean.success(i${entity}Service.page(new Page<>(page,size)));}#foreach($field in ${table.fields})#if(${field.keyFlag})/*** 獲取指定$!{table.comment}* @param id $!{table.comment}ID* @return ResponseBean*/@ApiOperation(value = "獲取指定$!{table.comment}",notes = "獲取指定$!{table.comment}")@RequestMapping(value = "/{id}",method = {RequestMethod.GET})public ResponseBean get(@PathVariable(value = "id") ${field.propertyType} id){${entity} ${table.entityPath} = i${entity}Service.getById(id);if(${table.entityPath} != null){return ResponseBean.success("查詢成功",${table.entityPath});}else{return ResponseBean.error("查詢失敗");}}/*** 添加指定$!{table.comment}* @param ${table.entityPath} $!{table.comment}* @return ResponseBean*/@ApiOperation(value = "添加指定$!{table.comment}",notes = "添加指定$!{table.comment}")@RequestMapping(value = "/add",method = {RequestMethod.POST})public ResponseBean post(@RequestBody ${entity} ${table.entityPath}){${table.entityPath}.setId(null);if(i${entity}Service.save(${table.entityPath})){return ResponseBean.success("添加成功", ${table.entityPath});}else{return ResponseBean.error("添加失敗");}}/*** 更新指定$!{table.comment}* @param id $!{table.comment}ID* @param ${table.entityPath} $!{table.comment}* @return ResponseBean*/@ApiOperation(value = "更新指定$!{table.comment}",notes = "更新指定$!{table.comment}")@RequestMapping(value = "/{id}",method = {RequestMethod.PUT})public ResponseBean put(@PathVariable(value = "id") ${field.propertyType} id,@RequestBody ${entity} ${table.entityPath}){${table.entityPath}.setId(id);if(i${entity}Service.updateById(${table.entityPath})){return ResponseBean.success("更新成功");}else{return ResponseBean.error("更新失敗");}}/*** 刪除指定$!{table.comment}* @param id $!{table.comment}ID* @return ResponseBean*/@ApiOperation(value = "刪除指定$!{table.comment}",notes = "刪除指定$!{table.comment}")@RequestMapping(value = "/{id}",method = {RequestMethod.DELETE})public ResponseBean delete(@PathVariable(value = "id") ${field.propertyType} id){if(i${entity}Service.removeById(id)){return ResponseBean.success("刪除成功");}else{return ResponseBean.error("刪除失敗");}}#end#end }#end參考文章
基于mybatis-plus的代碼自動生成工具(自定義模板)
MyBatis Plus Generator——MyBatis Plus代碼生成器DEMO
總結
以上是生活随笔為你收集整理的MyBatis Plus Generator——基于Velocity的Controller参考模板(集成MyBatis Plus、Swagger2、自封装Response、分页)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MyBatis Plus Generat
- 下一篇: Spring Session——@Ena