JPA反向工程生成模板

easycode反向工程生成DAO service层:

通过创建好的数据库使用的技术是jpa

安装easycode:

我使用的是idea进行生成代码,在plugins安装easycode
在这里插入图片描述

设置easycode,在模板配置配置jpa:

在这里插入图片描述

首先添加分组,我命名为jpa,然后再依次添加生成dao层service层的jpa代码模板。

service:

##定义初始变量

#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;import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};

import java.util.List;/**

* $!{tableInfo.comment}($!{tableInfo.name})表服务接口

*

* @author $!author

* @since $!time.currTime()*/

public interface $!{tableName} {
}

serviceImpl:

##定义初始变量

#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}.entity.$!{tableInfo.name};

import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;

import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;

import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

import javax.annotation.Resource;

import java.util.List;/**

* $!{tableInfo.comment}($!{tableInfo.name})表服务实现类

*

* @author $!author

* @since $!time.currTime()*/@Service

@Transactionalpublic class $!{tableName} implements $!{tableInfo.name}Service {
@Resourceprivate $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;

}

dao:

##定义初始变量

#set($tableName = $tool.append($tableInfo.name, "Dao"))

##设置回调

$!callback.setFileName($tool.append($tableName, ".java"))

$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))

##拿到主键#if(!$tableInfo.pkColumn.isEmpty())#set($pk = $tableInfo.pkColumn.get(0))

#set($pkType = $tableInfo.pkColumn.get(0).shortType)

#end#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;import $!{tableInfo.savePackageName}.entity.Base$!{tableInfo.name};

import com.acmtc.common.dao.IRepository;/**

* $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层

*

* @author $!author

* @since $!time.currTime()*/

public interface $!{tableName} extends IRepository{
}

entity:

##引入宏定义

$!define

##定义初始变量

#set($entityName = $tool.append("Base", $tableInfo.name))

##设置回调

$!callback.setFileName($tool.append($entityName, ".java"))

$!callback.setSavePath($tool.append($tableInfo.savePath, "/entity"))

##使用宏定义设置包后缀

#setPackageSuffix("entity")

##使用全局变量实现默认包导入

$!autoImport

import javax.persistence.Column;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

import javax.persistence.Table;

import javax.persistence.Entity;

import org.hibernate.annotations.GenericGenerator;

import java.io.Serializable;

##使用宏定义实现类注释信息

#tableComment("实体类")

@Entity

@Table(name="$!{tableInfo.obj.name}")

public class $!{entityName} implements Serializable {
private static final long serialVersionUID = $!tool.serial();

#foreach($column in $tableInfo.fullColumn)

#if(${column.comment})/**

* ${column.comment}

*/#end

#if(${velocityCount} == 1)

@Id

@Column(name = "$column.obj.getName()")

@GenericGenerator(name = "system-uuid", strategy = "uuid")

@GeneratedValue(generator = "system-uuid")

#else

@Column(name = "$column.obj.getName()")

#end

private $!{tool.getClsNameByFullName($column.type)} $!{column.name};

#end

#foreach($column in $tableInfo.fullColumn)

##使用宏定义实现get,set方法

#getSetMethod($column)

#end

}

配置完成:

就可以连接数据库,右击选中的表,选中easycode,使用自己配置好的模板即可

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值