IDEA 代码自动生成

安装必要插件:Easy Code、Database

配置想要格式的模板:

 常用实体类模板:

##引入宏定义
$!define

##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", "DO.java")

##使用宏定义设置包后缀
#setPackageSuffix("entity")
##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

##使用宏定义实现类注释信息
/**
 * $!{tableInfo.comment}($!{tableInfo.name})实体类
 *
 * @author liuhuashan
 * @since $!time.currTime()
 */
@Data
@ApiModel(description = "$!{tableInfo.comment}($!{tableInfo.name})实体类")
public class $!{tableInfo.name}DO implements Serializable {

    private static final long serialVersionUID = $!tool.serial();

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")
    #end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};

#end
}

mapper中resultMap: 

##引入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

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="$!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}DO" id="result$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name" />
#end
    </resultMap>

    

</mapper>

使用Database连接数据库:

 easyexcel实体类模板:

##引入宏定义
$!define

##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", "DO.java")

##使用宏定义设置包后缀
#setPackageSuffix("entity")
##使用全局变量实现默认包导入
$!autoImport
import com.alibaba.excel.annotation.ExcelProperty;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

##使用宏定义实现类注释信息
/**
 * $!{tableInfo.comment}($!{tableInfo.name})实体类
 *
 * @author liuhuashan
 * @since $!time.currTime()
 */
@Data
@ApiModel(description = "$!{tableInfo.comment}($!{tableInfo.name})实体类")
public class $!{tableInfo.name}DO implements Serializable {

    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)

    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")   
    @ExcelProperty("${column.comment}")
    #end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end

}

视图实体类: 

##引入宏定义
$!define

##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", "VO.java")

##使用宏定义设置包后缀
#setPackageSuffix("entity")
##使用全局变量实现默认包导入
$!autoImport
import com.rate.common.core.annotation.Excel;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

##使用宏定义实现类注释信息
/**
 * $!{tableInfo.comment}($!{tableInfo.name})实体类
 *
 * @author liuhuashan
 * @since $!time.currTime()
 */
@Data
@ApiModel(description = "$!{tableInfo.comment}($!{tableInfo.name})实体类")
public class $!{tableInfo.name}VO implements Serializable {

    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)

    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")   
    @Excel(name = "${column.comment}")
    #end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值