日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

MyBatis Plus Generator——基于Velocity的Controller参考模板(集成MyBatis Plus、Swagger2、自封装Response、分页)

發(fā)布時(shí)間:2024/10/5 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MyBatis Plus Generator——基于Velocity的Controller参考模板(集成MyBatis Plus、Swagger2、自封装Response、分页) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

代碼生成器

MyBatis Plus Generator——MyBatis Plus代碼生成器DEMO

解決方案

包含:MyBatis Plus、Swagger2、自封裝Response、MyBatis Plus分頁(yè)插件、主鍵類型判斷

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}分頁(yè)* @return ResponseBean*/@ApiOperation(value = "$!{table.comment}分頁(yè)查詢",notes = "$!{table.comment}分頁(yè)查詢")@ResponseBody@RequestMapping(value = "/page",method = {RequestMethod.GET})public ResponseBean page(@ApiParam(name = "page",value = "頁(yè)數(shù)")@RequestParam(defaultValue = DEFAULT_PAGE_NUM) Integer page,@ApiParam(name = "size",value = "記錄數(shù)")@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的代碼自動(dòng)生成工具(自定義模板)

MyBatis Plus Generator——MyBatis Plus代碼生成器DEMO

總結(jié)

以上是生活随笔為你收集整理的MyBatis Plus Generator——基于Velocity的Controller参考模板(集成MyBatis Plus、Swagger2、自封装Response、分页)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。