1,idea安装easyCode插件
2,设置模板
easyCode的教程:https://gitee.com/makejava/EasyCode/wikis
easyCode会有默认的字段类型的对应关系,也可以根据需要自己修改
下面是我自己写的一套(适用于mybatisPlus)
##导入宏定义 $!define ##保存文件(宏定义) #save("/entity", ".java") ##包路径(宏定义) #setPackageSuffix("entity") ##自动导入包(全局变量) $!autoImport import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable; import com.cfam.ruleengine.common.base.BaseEntity; import lombok.EqualsAndHashCode; import lombok.Data; ##表注释(宏定义) #tableComment("表实体类") @SuppressWarnings("serial") @EqualsAndHashCode(callSuper = true) @TableName("$!tableInfo.obj.name") @Data public class $!{tableInfo.name} extends BaseEntity { #foreach($column in $tableInfo.fullColumn) #if(${column.name}!="id" && ${column.name}!="createUser" && ${column.name}!="updateUser" && ${column.name}!="createTime" && ${column.name}!="updateTime") #if(${column.comment})/** * ${column.comment} */#end #if(${column.name.indexOf("Id")}!=-1) private Long $!{column.name}; #else private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end #end #end }entity
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("Mapper") ##保存文件(宏定义) #save("/Mapper", "Mapper.java") ##包路径(宏定义) #setPackageSuffix("mapper") import com.baomidou.mybatisplus.core.mapper.BaseMapper; import $!{tableInfo.savePackageName}.entity.$!tableInfo.name; ##表注释(宏定义) #tableComment("表数据库访问层") public interface $!{tableName} extends BaseMapper<$!tableInfo.name> { }mapper
##导入宏定义 $!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> { }service
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("ServiceImpl") ##保存文件(宏定义) #save("/service/impl", "ServiceImpl.java") ##包路径(宏定义) #setPackageSuffix("service.impl") import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper; import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import org.springframework.stereotype.Service; ##表注释(宏定义) #tableComment("表服务实现类") @Service("$!tool.firstLowerCase($tableInfo.name)Service") public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service { }service.impl
##导入宏定义 $!define ##设置表后缀(宏定义) #setTableSuffix("Controller") ##保存文件(宏定义) #save("/controller", "Controller.java") ##包路径(宏定义) #setPackageSuffix("controller") ##定义服务名 #set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service")) ##定义实体对象名 #set($entityName = $!tool.firstLowerCase($!tableInfo.name)) import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import $!{tableInfo.savePackageName}.entity.dto.$!{tableInfo.name}QueryReq; import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name}; import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; import org.springframework.web.bind.annotation.*; import com.cfam.common.base.controller.BaseController; import com.baomidou.mybatisplus.core.metadata.IPage; import com.cfam.common.base.dto.resp.RespDTO; import org.springframework.beans.BeanUtils; import lombok.extern.slf4j.Slf4j; import javax.annotation.Resource; ##表注释(宏定义) #tableComment("表控制层") @RestController @Slf4j public class $!{tableName} extends BaseController { /** * 服务对象 */ @Resource private $!{tableInfo.name}Service $!{serviceName}; /** * 分页查询$!{tableInfo.comment} * * @param req 查询实体 * @return 所有数据 */ @GetMapping(value = "$!tool.firstLowerCase($!tableInfo.name)/selectPage") public RespDTO<IPage<$!tableInfo.name>> selectPage(@RequestBody $!{tableInfo.name}QueryReq req) { try { $!tableInfo.name $tool.firstLowerCase($!tableInfo.name) = new $!{tableInfo.name}(); BeanUtils.copyProperties(req, $tool.firstLowerCase($!tableInfo.name)); QueryWrapper queryWrapper = new QueryWrapper($tool.firstLowerCase($!tableInfo.name)); queryWrapper.orderByDesc("create_time"); return success(this.$!{serviceName}.page(new Page<>(req.getPageNum(), req.getPageSize()), queryWrapper)); }catch (Exception e){ log.error("分页查询$!{tableInfo.comment}出错",e); return fail("500", e.getMessage()); } } }controller
##定义初始变量 #set($tableName = $tool.append($tableInfo.name, "QueryReq")) ##设置回调 $!callback.setFileName($tool.append($tableName, ".java")) $!callback.setSavePath($tool.append($tableInfo.savePath, "/entity/dto")) #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.entity.dto#{end}; ##使用全局变量实现默认包导入 $!autoImport import com.cfam.api.datacenter.dto.data.EntityDTO; import lombok.Data; import lombok.EqualsAndHashCode; /** * ($!{tableInfo.comment})$!{tableInfo.name} 查询 请求参数 * @author makejava * @date $!time.currTime() */ @Data public class $!{tableInfo.name}QueryReq implements EntityDTO{ #foreach($column in $tableInfo.fullColumn) #if(${column.comment})/** * ${column.comment} */#end private $!{tool.getClsNameByFullName($column.type)} $!{column.name}; #end private Integer pageSize; private Integer pageNum; }QueryReq
3,velocity语法
一些基本介绍:http://www.51gjie.com/javaweb/896.html
标签:tableInfo,插件,name,##,column,idea,easyCode,import,定义 From: https://www.cnblogs.com/hsql/p/17984488