
EasyCode-代码模板生成工具
what
EasyCode是基于IntelliJ IDEA Ultimate版开发的一个代码生成插件,主要通过自定义模板(基于velocity)来生成各种你想要的代码。
why
项目中添加新的数据表时,可以直接生成基于自定义模板的基础类,节省基础编码开发时间,提高效率。
how
1、安装插件
Settings -> Plugins -> easy code(install -> restart Idea)
2、导入
Settings -> Other Settings -> Easy Code
导入模板 -> token:8cf91ffdd5fee2abc01198cc44b60d7b(6小时有效)
3、生成
选择要生成的表,右键
选择包、路径(支持模块)及要生成的代码模板
生成的代码模板样例(表名:apply_asset)
4、代码
## -------- model start --------
##引入宏定义
$!define
##使用宏定义设置回调(保存位置与文件后缀)
#save("/model", ".java")
##使用宏定义设置包后缀
#setPackageSuffix("model")
#set($tableName = $tableInfo.name)
$!callback.setFileName($tool.append($tableName, ".java"))
##使用全局变量实现默认包导入
$!autoImport
import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import lombok.Data;
import org.hibernate.annotations.*;
##使用宏定义实现类注释信息
/**
* @author $!author
* @description $!{tableInfo.comment}($!{tableInfo.name})实体类
* @date $!time.currTime()
* @since 1.0
*/
@Entity
@Table(name = $tool.append('"', $tableInfo.obj.name, '"'))
@Data
@DynamicInsert
@DynamicUpdate
public class $!{tableName} implements Serializable {
// TODO private static final long serialVersionUID = -1L;
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})
/**
* ${column.comment}
*/
#end
#if($!{column.obj.name} == 'id')
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
#elseif($!{column.obj.name} == 'created_time')
@CreationTimestamp
#elseif($!{column.obj.name} == 'modified_time')
@UpdateTimestamp
#end
@Column(name = $tool.append('"', $column.obj.name ,'"'))
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
## -------- model end --------
## -------- dao start --------
##设置回调
$!callback.setFileName($tool.append($tableInfo.name, "Dao.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}#{end}.dao;
import com.linkmed.core.dao.BaseDao;
/**
* @author $!author
* @description $!{tableInfo.comment}($tableInfo.obj.name)}数据操作接口层
* @date $!time.currTime()
* @since 1.0
*/
public interface ${tableInfo.name}Dao extends BaseDao {
}
## -------- dao end --------
## -------- dao impl start --------
##设置回调
$!callback.setFileName($tool.append($tableInfo.name, "DaoImpl.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao/impl"))
package $!{tableInfo.savePackageName}.dao.impl;
import com.linkmed.core.dao.hibernate.BaseDaoHibernate;
import $!{tableInfo.savePackageName}.dao.${tableInfo.name}Dao;
import org.springframework.stereotype.Component;
/**
* @author $!author
* @description $!{tableInfo.comment}($tableInfo.obj.name)数据操作层
* @date $!time.currTime()
* @since 1.0
*/
@Component
public class ${tableInfo.name}DaoImpl extends BaseDaoHibernate implements ${tableInfo.name}Dao {
}
## -------- dao impl end --------
## -------- service start --------
##设置回调
$!callback.setFileName($tool.append($tableInfo.name, "Service.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
package $!{tableInfo.savePackageName}.service;
/**
* @author $!author
* @description $!{tableInfo.comment}($tableInfo.obj.name)业务操作接口层
* @date $!time.currTime()
* @since 1.0
*/
public interface ${tableInfo.name}Service {
}
## -------- service end --------
## -------- service impl start --------
##设置回调
$!callback.setFileName($tool.append($tableInfo.name, "ServiceImpl.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
package $!{tableInfo.savePackageName}.service.impl;
import $!{tableInfo.savePackageName}.dao.${tableInfo.name}Dao;
import $!{tableInfo.savePackageName}.service.${tableInfo.name}Service;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author $!author
* @description $!{tableInfo.comment}($tableInfo.obj.name)业务操作接口层
* @date $!time.currTime()
* @since 1.0
*/
@Service
public class ${tableInfo.name}ServiceImpl implements ${tableInfo.name}Service {
@Autowired
private ${tableInfo.name}Dao $tool.firstLowerCase(${tableInfo.name})Dao;
}
## -------- service impl end --------
other
学习文档:https://gitee.com/makejava/EasyCode/wikis/pages
使用debug查看一些对象方法:
Settings -> EasyCode -> Template Setting
end
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 蚂蚁工匠
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果