标签:style long str val auto 定义 rest mamicode interface
作用:自动生成模板代码和实体类,简化开发人员工作,降低错误率。
1.entity
##导入宏定义 $!define ##保存文件(宏定义) #save("/entity", ".java") ##包路径(宏定义) #setPackageSuffix("entity") ##自动导入包(全局变量) $!autoImport import com.baomidou.mybatisplus.extension.activerecord.Model; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; import java.io.Serializable; ##表注释(宏定义) #tableComment("表实体类") @Data @ApiModel(value="$!{tableInfo.name}",description="$tableInfo.comment") public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> implements Serializable { private static final long serialVersionUID = $!tool.serial(); #foreach($column in $tableInfo.fullColumn) ##if(${column.comment})/** ##* ${column.comment} ##*/#end @ApiModelProperty(name = "$!{column.name}", value = "$column.comment", example = "11") private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end }
2.dao
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("Dao") ##保存文件(宏定义) #save("/dao", "Dao.java") ##包路径(宏定义) #setPackageSuffix("dao") import com.baomidou.mybatisplus.core.mapper.BaseMapper; import $!{tableInfo.savePackageName}.entity.$!tableInfo.name; import org.apache.ibatis.annotations.Mapper; ##表注释(宏定义) #tableComment("表数据库访问层") @Mapper public interface $!{tableName} extends BaseMapper<$!tableInfo.name> { }
3.impl
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("ServiceImpl") ##保存文件(宏定义) #save("/service/impl", "ServiceImpl.java") ##包路径(宏定义) #setPackageSuffix("service.impl") import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao; import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import org.springframework.stereotype.Service; ##表注释(宏定义) #tableComment("表服务实现类") @Service public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Dao, $!{tableInfo.name}> implements $!{tableInfo.name}Service { }
4.service
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("Service") ##保存文件(宏定义) #save("/service", "Service.java") ##包路径(宏定义) #setPackageSuffix("service") import com.baomidou.mybatisplus.extension.service.IService; import $!{tableInfo.savePackageName}.entity.$!tableInfo.name; ##表注释(宏定义) #tableComment("表服务接口") public interface $!{tableName} extends IService<$!tableInfo.name> { }
5.controller
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("Controller") ##保存文件(宏定义) #save("/controller", "Controller.java") ##包路径(宏定义) #setPackageSuffix("controller") ##定义服务名 #set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) ##定义实体对象名 #set($entityName = $!tool.firstLowerCase($!tableInfo.name)) #set($PkType = $!{tool.getClsNameByFullName($!tableInfo.pkColumn[0].type)}) import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.api.ApiController; import com.baomidou.mybatisplus.extension.api.R; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import $!{tableInfo.savePackageName}.entity.$!tableInfo.name; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; ##表注释(宏定义) #tableComment("表控制层") @RestController @Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})") @RequestMapping("$!tool.firstLowerCase($!tableInfo.name)") public class $!{tableName} extends ApiController { /** * 服务对象 */ @Resource private $!{tableInfo.name}Service $!{serviceName}; /** * 分页查询所有数据 * * @param page 分页对象 * @param $!entityName 查询实体 * @return 所有数据 */ @GetMapping("/selectAll") @ApiOperation(value = "分页查全部") public R selectAll(Page<$!tableInfo.name> page, @ApiParam $!tableInfo.name $!entityName) { return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName))); } /** * 通过主键查询单条数据 * * @param id 主键 * @return 单条数据 */ @GetMapping("{id}") @ApiOperation(value = "根据id查") public R selectOne(@PathVariable("id") $!{PkType} id) { return success(this.$!{serviceName}.getById(id)); } /** * 新增数据 * * @param $!entityName 实体对象 * @return 新增结果 */ @PostMapping("/add") @ApiOperation(value = "添加") public R insert(@RequestBody $!tableInfo.name $!entityName) { return success(this.$!{serviceName}.save($!entityName)); } /** * 修改数据 * * @param $!entityName 实体对象 * @return 修改结果 */ @PutMapping("/update") @ApiOperation(value = "更新") public R update(@RequestBody $!tableInfo.name $!entityName) { return success(this.$!{serviceName}.updateById($!entityName)); } /** * 删除数据 * * @param idList 主键结合 * @return 删除结果 */ @DeleteMapping("/del") @ApiOperation(value = "删除") public R delete(@RequestParam("idList") List<$!{PkType}> idList) { return success(this.$!{serviceName}.removeByIds(idList)); } }
idea系列---【EsayCode插件自定义Mybatis-Plus+Lombook+Swagger模板】
标签:style long str val auto 定义 rest mamicode interface
原文地址:https://www.cnblogs.com/hujunwei/p/14698294.html