微前端架构如何改变企业的开发模式与效率提升
1038
2023-03-01
IDEA插件EasyCode及MyBatis最优配置步骤详解
具体安装步骤,不再赘述,仅附上个人工作、学习中的对 EasyCode 的详细配置。
插件链接地址:https://gitee.com/makejava/EasyCode
Type Mapper
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
Template Setting
entity.java
##初始化定义
$!init
##引入宏定义
$!define
##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("entity")
##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;
##使用宏定义实现类注释信息
#tableComment("实体类")
public class $!{tableInfo.name} implements Serializable {
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})/**
* ${column.comment}
*/#end
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
public $!{tableInfo.name}() {
}
public $!{tableInfo.name}(#foreach($column in $tableInfo.fullColumn)$!{tool.getClsNameByFullName($column.type)} $!column.name #if($velocityCount != $tableInfo.fullColumn.size()), #end#end) {
#foreach($column in $tableInfo.fullColumn) this.$!column.name = $!column.name;#end
}
#foreach($column in $tableInfo.fullColumn)
##使用宏定义实现get,set方法
#getSetMethod($column)
#end
@Override
public String toString() {
StringBuilder str = new StringBuilder();
str.append("$!{tableInfo.name}{");
#foreach( $column in $tableInfo.fullColumn )
str.append("$!column.name=").append(this.$!column.name)#if( $foreach.hasNext ).append(", ")#end;
#end
str.append('}');
return str.toString();
}
}
DTO.java
##导入宏定义
$!define
##保存文件(宏定义)
#save("/dto", "DTO.java")
##包路径(宏定义)
#setPackageSuffix("dto")
##自动导入包(全局变量)
$!autoImport
##import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.io.Serializable;
import lombok.Data;
##import com.baomidou.mybatisplus.annotation.IdType;
##import com.baomidou.mybatisplus.annotation.TableId;
##表注释(宏定义)
#tableComment("DTO")
@Data
public class $!{tableInfo.name}DTO implements Serializable {
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $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};
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.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
public interface $!{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 条数
*/
int queryAllCount($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 新增数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 影响行数NOyTnfnCnl
*/
int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 新增选择列
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 影响行数
*/
int insertSelective($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 修改数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 影响行数
*/
int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 通过主键删除数据
*
* @param $!pk.name 主键
* @return 影响行数
*/
int deleteById($!pk.shortType $!pk.name);
/**
* 批量新增
* @param recordList
* @return 影响行数
*/
int batchInsert(@Param("recordList") List<$!{tableInfo.name}> recordList);
/**
* 批量修改
* @param recordList
* @return 影响行数
*/
int batchUpdate(@Param("recordList") List<$!{tableInfo.name}> recordList);
/**
* 根据主键批量删除
* @param ids 主键s
* @return 影响行数
*/
int batchDelete(@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;
import org.springframework.stereotype.Service;
import org.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")
public class $!{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
*/
public interface $!{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;
import org.springframework.beans.factory.annotation.Autowired;
import org.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)")
public class $!{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($column in $tableInfo.fullColumn)
#end
#foreach($column in $tableInfo.fullColumn)
a.$!column.obj.name AS $!column.name #if($velocityCount != $tableInfo.fullColumn.size()),#end
#end
#foreach($column in $tableInfo.fullColumn)
and a.$!column.obj.name = #{$!column.name}
#end
select
from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
where a.$!pk.obj.name = #{$!pk.name}
select
from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
select
count(1)
from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values (#foreach($column in $tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
#foreach($column in $tableInfo.fullColumn)
$!column.obj.name,
#end
#foreach($column in $tableInfo.fullColumn)
#{$!column.name,jdbcType=$!column.ext.jdbcType},
#end
update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
#foreach($column in $tableInfo.otherColumn)
$!column.obj.name = #{$!column.name},
#end
where $!pk.obj.name = #{$!pk.name}
delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} (
#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end
)
values
(
#foreach($column in $tableInfo.fullColumn)#{item.$!{column.name}}#if($velocityHasNext), #end#end
)
update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
#foreach($column in $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.name in(
#{item.$!pk.name}
)
delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name in (
#{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($column in $tableInfo.fullColumn)
#end
#foreach($column in $tableInfo.fullColumn)
a.$!column.obj.name AS $!column.name #if($velocityCount != $tableInfo.fullColumn.size()),#end
#end
#foreach($column in $tableInfo.fullColumn)
and a.$!column.obj.name = #{$!column.name}
#end
select
from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
where a.$!pk.obj.name = #{$!pk.name}
select
from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
select
counNOyTnfnCnlt(1)
from $!{tableInfo.obj.parent.name}.$!tableInfo.obj.name a
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}(#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values (#foreach($column in $tableInfo.fullColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
#foreach($column in $tableInfo.fullColumn)
$!column.obj.name,
#end
#foreach($column in $tableInfo.fullColumn)
#{$!column.name,jdbcType=$!column.ext.jdbcType},
#end
update $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name}
#foreach($column in $tableInfo.otherColumn)
$!column.obj.name = #{$!column.name},
#end
where $!pk.obj.name = #{$!pk.name}
delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
insert into $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} (
#foreach($column in $tableInfo.fullColumn)$!column.obj.name#if($velocityHasNext), #end#end
)
(
(
select
#foreach($column in $tableInfo.fullColumn)#{item.$!{column.name}}#if($velocityHasNext), #end#end
from dual
)
)
begin
update $!{tableInfo.obj.parent.name}.$!{tableInfo.http://obj.name}
#foreach($column in $tableInfo.otherColumn)
$!column.obj.name = #{item.$!column.name}
#end
where ID = #{item.$!pk.obj.name}
;end;
delete from $!{tableInfo.obj.parent.name}.$!{tableInfo.obj.name} where $!pk.obj.name in (
#{item}
)
Global Config
init
##初始化区域
##去掉表的t_前缀
#if($tableInfo.obj.name.startsWith("t_"))
$!tableInfo.setName($tool.getClassName($tableInfo.obj.name.substring(2)))
#end
##参考阿里巴巴开发手册,POJO 类中布尔类型的变量,都不要加 is 前缀,否则部分框架解析会引起序列化错误
#foreach($column in $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($item in $temp)
#set($newList = $tool.newArrayList())
#foreach($column in $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($column in $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};
}
public void set$!{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();
#else this.$!{column.name} = $!{column.name};#end}
#end
mybatisSupport
##针对Mybatis 进行支持,主要用于生成xml文件
#foreach($column in $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($column in $tableInfo.fullColumn)$column.obj.name#if($velocityHasNext), #end#end#end
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~