IDEA插件EasyCode及MyBatis最优配置步骤详解
具体安装步骤,不再赘述,仅附上个人工作、学习中的对EasyCode的详细配置。
插件链接地址:https://gitee.com/makejava/EasyCode
TypeMapper
varchar(\(\d+\))? java.lang.String char(\(\d+\))? java.lang.String text java.lang.String decimal(\(\d+\))? java.lang.Double decimal(\(\d+,\d+\))? java.lang.Double integer java.lang.Integer int(\(\d+\))? java.lang.Integer int4 java.lang.Integer int8 java.lang.Long bigint(\(\d+\))? java.lang.Long datetime(\(\d+\))? java.time.LocalDateTime timestamp java.time.LocalDateTime boolean java.lang.Boolean tinyint(\(\d+\))? java.lang.Integer smallint(\(\d+\))? java.lang.Integer double(\(\d+\))? java.lang.Double double(\(\d+,\d+\))? java.lang.Double
TemplateSetting
entity.java
##初始化定义 $!init ##引入宏定义 $!define ##使用宏定义设置回调(保存位置与文件后缀) #save("/entity",".java") ##使用宏定义设置包后缀 #setPackageSuffix("entity") ##使用全局变量实现默认包导入 $!autoImport importjava.io.Serializable; ##使用宏定义实现类注释信息 #tableComment("实体类") publicclass$!{tableInfo.name}implementsSerializable{ privatestaticfinallongserialVersionUID=$!tool.serial(); #foreach($columnin$tableInfo.fullColumn) #if(${column.comment})/** *${column.comment} */#end private$!{tool.getClsNameByFullName($column.type)}$!{column.name}; #end public$!{tableInfo.name}(){ } public$!{tableInfo.name}(#foreach($columnin$tableInfo.fullColumn)$!{tool.getClsNameByFullName($column.type)}$!column.name#if($velocityCount!=$tableInfo.fullColumn.size()),#end#end){ #foreach($columnin$tableInfo.fullColumn)this.$!column.name=$!column.name;#end } #foreach($columnin$tableInfo.fullColumn) ##使用宏定义实现get,set方法 #getSetMethod($column) #end @Override publicStringtoString(){ StringBuilderstr=newStringBuilder(); str.append("$!{tableInfo.name}{"); #foreach($columnin$tableInfo.fullColumn) str.append("$!column.name=").append(this.$!column.name)#if($foreach.hasNext).append(",")#end; #end str.append('}'); returnstr.toString(); } }
DTO.java
##导入宏定义 $!define ##保存文件(宏定义) #save("/dto","DTO.java") ##包路径(宏定义) #setPackageSuffix("dto") ##自动导入包(全局变量) $!autoImport ##importcom.baomidou.mybatisplus.extension.activerecord.Model; importjava.io.Serializable; importlombok.Data; ##importcom.baomidou.mybatisplus.annotation.IdType; ##importcom.baomidou.mybatisplus.annotation.TableId; ##表注释(宏定义) #tableComment("DTO") @Data publicclass$!{tableInfo.name}DTOimplementsSerializable{ privatestaticfinallongserialVersionUID=$!tool.serial(); #foreach($columnin$tableInfo.fullColumn) #if(${column.comment})/**${column.comment}*/#end private$!{tool.getClsNameByFullName($column.type)}$!{column.name}; #end }
mapper.java
##定义初始变量 #set($tableName=$tool.append($tableInfo.name,"Mapper")) ##设置回调 $!callback.setFileName($tool.append($tableName,".java")) $!callback.setSavePath($tool.append($tableInfo.savePath,"/mapper")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk=$tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package$!{tableInfo.savePackageName}.#{end}mapper; import$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}; importorg.apache.ibatis.annotations.Mapper; importorg.apache.ibatis.annotations.Param; importjava.util.List; #set($time=$!time.currTime()) #set($time=$time.substring(0,11)) #set($time=$time.replace("-","/")) /** **$!{tableInfo.comment}($!{tableInfo.name})表数据库访问层 *
* *@author:$!author *@date:$!time */ @Mapper publicinterface$!{tableName}{ /** *通过ID查询单条数据 * *@param$!pk.name主键 *@return实例对象 */ $!{tableInfo.name}queryById($!pk.shortType$!pk.name); /** *通过实体作为筛选条件查询 * *@param$!tool.firstLowerCase($!{tableInfo.name})实例对象 *@return对象列表 */ List<$!{tableInfo.name}>queryAll($!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name})); /** *通过实体作为筛选条件查询条数 * *@param$!tool.firstLowerCase($!{tableInfo.name})实例对象 *@return条数 */ intqueryAllCount($!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name})); /** *新增数据 * *@param$!tool.firstLowerCase($!{tableInfo.name})实例对象 *@return影响行数 */ intinsert($!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name})); /** *新增选择列 * *@param$!tool.firstLowerCase($!{tableInfo.name})实例对象 *@return影响行数 */ intinsertSelective($!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name})); /** *修改数据 * *@param$!tool.firstLowerCase($!{tableInfo.name})实例对象 *@return影响行数 */ intupdate($!{tableInfo.name}$!tool.firstLowerCase($!{tableInfo.name})); /** *通过主键删除数据 * *@param$!pk.name主键 *@return影响行数 */ intdeleteById($!pk.shortType$!pk.name); /** *批量新增 *@paramrecordList *@return影响行数 */ intbatchInsert(@Param("recordList")List<$!{tableInfo.name}>recordList); /** *批量修改 *@paramrecordList *@return影响行数 */ intbatchUpdate(@Param("recordList")List<$!{tableInfo.name}>recordList); /** *根据主键批量删除 *@paramids主键s *@return影响行数 */ intbatchDelete(@Param("ids")String[]ids); }
serviceImpl.java
##初始化定义 $!init ##定义初始变量 #set($tableName=$tool.append($tableInfo.name,"ServiceImpl")) ##设置回调 $!callback.setFileName($tool.append($tableName,".java")) $!callback.setSavePath($tool.append($tableInfo.savePath,"/service/impl")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk=$tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package$!{tableInfo.savePackageName}.#{end}service.impl; import$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper; import$!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; importorg.springframework.stereotype.Service; importorg.springframework.beans.factory.annotation.Autowired; #set($time=$!time.currTime()) #set($time=$time.substring(0,11)) #set($time=$time.replace("-","/")) /** **$!{tableInfo.comment}($!{tableInfo.name})表服务实现类 *
* *@author:$!author *@date:$!time */ @Service("/$!tool.firstLowerCase($!{tableInfo.name})Service") publicclass$!{tableName}implements$!{tableInfo.name}Service{ @Autowired private$!{tableInfo.name}Mapper$!tool.firstLowerCase($!{tableInfo.name})Mapper; }
service.java
##定义初始变量 #set($tableName=$tool.append($tableInfo.name,"Service")) ##设置回调 $!callback.setFileName($tool.append($tableName,".java")) $!callback.setSavePath($tool.append($tableInfo.savePath,"/service")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk=$tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package$!{tableInfo.savePackageName}.#{end}service; #set($time=$!time.currTime()) #set($time=$time.substring(0,11)) #set($time=$time.replace("-","/")) /** **$!{tableInfo.comment}($!{tableInfo.name})表服务接口 *
* *@author:$!author *@date:$!time */ publicinterface$!{tableName}{ }
controller.java
##定义初始变量 #set($tableName=$tool.append($tableInfo.name,"Controller")) ##设置回调 $!callback.setFileName($tool.append($tableName,".java")) $!callback.setSavePath($tool.append($tableInfo.savePath,"/controller")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk=$tableInfo.pkColumn.get(0)) #end #if($tableInfo.savePackageName)package$!{tableInfo.savePackageName}.#{end}controller; import$!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service; importorg.springframework.beans.factory.annotation.Autowired; importorg.springframework.web.bind.annotation.*; #set($time=$!time.currTime()) #set($time=$time.substring(0,11)) #set($time=$time.replace("-","/")) /** **$!{tableInfo.comment}($!{tableInfo.name})表控制层 *
* *@author:$!author *@date:$!time */ @RestController @RequestMapping("/$!tool.firstLowerCase($tableInfo.name)") publicclass$!{tableName}{ @Autowired private$!{tableInfo.name}Service$!tool.firstLowerCase($tableInfo.name)Service; }
mysql-mapper.xml
##引入mybatis支持 $!mybatisSupport ##设置保存名称与保存位置 $!callback.setFileName($tool.append($!{tableInfo.name},"Mapper.xml")) $!callback.setSavePath($tool.append($modulePath,"/src/main/resources/mapper")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk=$tableInfo.pkColumn.get(0)) #end#foreach($columnin$tableInfo.fullColumn) #end #foreach($columnin$tableInfo.fullColumn) a.$!column.obj.nameAS$!column.name#if($velocityCount!=$tableInfo.fullColumn.size()),#end #end #foreach($columnin$tableInfo.fullColumn) anda.$!column.obj.name=#{$!column.name} #end select from$!{tableInfo.obj.parent.name}.$!tableInfo.obj.namea wherea.$!pk.obj.name=#{$!pk.name} select from$!{tableInfo.obj.parent.name}.$!tableInfo.obj.namea select count(1) from$!{tableInfo.obj.parent.name}.$!tableInfo.obj.namea insertinto$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($columnin$tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext),#end#end) values(#foreach($columnin$tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext),#end#end) insertinto$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} #foreach($columnin$tableInfo.fullColumn) $!column.obj.name, #end #foreach($columnin$tableInfo.fullColumn) #{$!column.name,jdbcType=$!column.ext.jdbcType}, #end update$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} #foreach($columnin$tableInfo.otherColumn) where$!pk.obj.name=#{$!pk.name}$!column.obj.name=#{$!column.name}, #end deletefrom$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}where$!pk.obj.name=#{$!pk.name} insertinto$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}( #foreach($columnin$tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext),#end#end ) values ( #foreach($columnin$tableInfo.fullColumn)#{item.$!{column.name}}#if($velocityHasNext),#end#end ) update$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} #foreach($columnin$tableInfo.otherColumn) when#{item.$!pk.name}then#{item.$!column.name} when#{item.$!pk.name}then$!{tableInfo.obj.name}.$!column.obj.name #end where$!pk.obj.namein( #{item.$!pk.name} ) deletefrom$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}where$!pk.obj.namein( #{item} )
oracle-mapper.xml
##引入mybatis支持 $!mybatisSupport ##设置保存名称与保存位置 $!callback.setFileName($tool.append($!{tableInfo.name},"Mapper.xml")) $!callback.setSavePath($tool.append($tableInfo.savePath,"/src/main/resources/mapper")) ##拿到主键 #if(!$tableInfo.pkColumn.isEmpty()) #set($pk=$tableInfo.pkColumn.get(0)) #end#foreach($columnin$tableInfo.fullColumn) #end #foreach($columnin$tableInfo.fullColumn) a.$!column.obj.nameAS$!column.name#if($velocityCount!=$tableInfo.fullColumn.size()),#end #end #foreach($columnin$tableInfo.fullColumn) anda.$!column.obj.name=#{$!column.name} #end select from$!{tableInfo.obj.parent.name}.$!tableInfo.obj.namea wherea.$!pk.obj.name=#{$!pk.name} select from$!{tableInfo.obj.parent.name}.$!tableInfo.obj.namea select count(1) from$!{tableInfo.obj.parent.name}.$!tableInfo.obj.namea insertinto$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($columnin$tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext),#end#end) values(#foreach($columnin$tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext),#end#end) insertinto$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} #foreach($columnin$tableInfo.fullColumn) $!column.obj.name, #end #foreach($columnin$tableInfo.fullColumn) #{$!column.name,jdbcType=$!column.ext.jdbcType}, #end update$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} #foreach($columnin$tableInfo.otherColumn) where$!pk.obj.name=#{$!pk.name}$!column.obj.name=#{$!column.name}, #end deletefrom$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}where$!pk.obj.name=#{$!pk.name} insertinto$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}( #foreach($columnin$tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext),#end#end ) ( ( select #foreach($columnin$tableInfo.fullColumn)#{item.$!{column.name}}#if($velocityHasNext),#end#end fromdual ) ) begin update$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} #foreach($columnin$tableInfo.otherColumn) $!column.obj.name=#{item.$!column.name} #end whereID=#{item.$!pk.obj.name} ;end;deletefrom$!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}where$!pk.obj.namein( #{item} )
GlobalConfig
init
##初始化区域 ##去掉表的t_前缀 #if($tableInfo.obj.name.startsWith("t_")) $!tableInfo.setName($tool.getClassName($tableInfo.obj.name.substring(2))) #end ##参考阿里巴巴开发手册,POJO类中布尔类型的变量,都不要加is前缀,否则部分框架解析会引起序列化错误 #foreach($columnin$tableInfo.fullColumn) #if($column.name.startsWith("is")&&$column.type.equals("java.lang.Boolean")) $!column.setName($tool.firstLowerCase($column.name.substring(2))) #end #end ##实现动态排除列 #set($temp=$tool.newHashSet("testCreateTime","otherColumn")) #foreach($itemin$temp) #set($newList=$tool.newArrayList()) #foreach($columnin$tableInfo.fullColumn) #if($column.name!=$item) ##带有反回值的方法调用时使用$tool.call来消除返回值 $tool.call($newList.add($column)) #end #end ##重新保存 $tableInfo.setFullColumn($newList) #end ##对importList进行篡改 #set($temp=$tool.newHashSet()) #foreach($columnin$tableInfo.fullColumn) #if(!$column.type.startsWith("java.lang.")) ##带有反回值的方法调用时使用$tool.call来消除返回值 $tool.call($temp.add($column.type)) #end #end ##覆盖 #set($importList=$temp)
define
##(Velocity宏定义) ##定义设置表名后缀的宏定义,调用方式:#setTableSuffix("Test") #macro(setTableSuffix$suffix) #set($tableName=$!tool.append($tableInfo.name,$suffix)) #end ##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix("Test") #macro(setPackageSuffix$suffix) #if($suffix!="")package#end#if($tableInfo.savePackageName!="")$!{tableInfo.savePackageName}.#{end}$!suffix; #end ##定义直接保存路径与文件名简化的宏定义,调用方式:#save("/entity",".java") #macro(save$path$fileName) $!callback.setSavePath($tool.append($tableInfo.savePath,$path)) $!callback.setFileName($tool.append($tableInfo.name,$fileName)) #end ##定义表注释的宏定义,调用方式:#tableComment("注释信息") #macro(tableComment$desc) #set($time=$!time.currTime()) #set($time=$time.substring(0,11)) #set($time=$time.replace("-","/")) /** **$!{tableInfo.comment}($!{tableInfo.name})$desc *
* *@author:$!author *@date:$!time */ #end ##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column) #macro(getSetMethod$column) public$!{tool.getClsNameByFullName($column.type)}get$!{tool.firstUpperCase($column.name)}(){ return$!{column.name}; } publicvoidset$!{tool.firstUpperCase($column.name)}($!{tool.getClsNameByFullName($column.type)}$!{column.name}){ #if(${column.type.equals("java.lang.String")})this.$!{column.name}=$!{column.name}==null?null:$!{column.name}.trim(); #elsethis.$!{column.name}=$!{column.name};#end} #end
mybatisSupport
##针对Mybatis进行支持,主要用于生成xml文件 #foreach($columnin$tableInfo.fullColumn) ##储存列类型 $tool.call($column.ext.put("sqlType",$tool.getField($column.obj.dataType,"typeName"))) #if($tool.newHashSet("java.lang.String").contains($column.type)) #set($jdbcType="VARCHAR") #elseif($tool.newHashSet("java.lang.Boolean","boolean").contains($column.type)) #set($jdbcType="BOOLEAN") #elseif($tool.newHashSet("java.lang.Byte","byte").contains($column.type)) #set($jdbcType="BYTE") #elseif($tool.newHashSet("java.lang.Integer","int","java.lang.Short","short").contains($column.type)) #set($jdbcType="INTEGER") #elseif($tool.newHashSet("java.lang.Long","long").contains($column.type)) #set($jdbcType="INTEGER") #elseif($tool.newHashSet("java.lang.Float","float","java.lang.Double","double").contains($column.type)) #set($jdbcType="NUMERIC") #elseif($tool.newHashSet("java.util.Date","java.sql.Timestamp","java.time.Instant","java.time.LocalDateTime","java.time.OffsetDateTime"," java.time.ZonedDateTime").contains($column.type)) #set($jdbcType="TIMESTAMP") #elseif($tool.newHashSet("java.sql.Date","java.time.LocalDate").contains($column.type)) #set($jdbcType="TIMESTAMP") #else ##其他类型 #set($jdbcType="OTHER") #end $tool.call($column.ext.put("jdbcType",$jdbcType)) #end ##定义宏,查询所有列 #macro(allSqlColumn)#foreach($columnin$tableInfo.fullColumn)$column.obj.name#if($velocityHasNext),#end#end#end
到此这篇关于IDEA插件EasyCodeMyBatis最优配置步骤详解的文章就介绍到这了,更多相关idea插件EasyCode内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!