EasyCode模板,配合通用mapper,dubbo项目使用
作者:互联网
EasyCode模板,配合通用mapper,dubbo项目使用
javadubbo通用Mapper在idea里下载easyCode插件,然后设置模板
一、entity(实体类)模板
##引入宏定义
$!define
#set($entityName = $tableInfo.name)
##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")
$!callback.setFileName($tool.append($entityName, ".java"))
##使用宏定义设置包后缀
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}entity;
##使用全局变量实现默认包导入
$!autoImport
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
##使用宏定义实现类注释信息
#tableComment("实体类")
@Table(name = "$tableInfo.obj.name")
@Data
@ApiModel(value = "$!{entityName})", description = "$!{tableInfo.comment}")
public class $!{entityName} implements Serializable {
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.pkColumn )
#if(${column.comment})/**
* ${column.comment}
*/
#end
@Id
@Column(name = "$column.obj.name")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
#foreach($column in $tableInfo.otherColumn)
#if(${column.comment})#end
@Column(name = "$column.obj.name")
@ApiModelProperty(value = "${column.comment}")
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
二、dao层模板
##定义初始变量
#set($entityName = $tableInfo.name)
#set($tableName = $tool.append($entityName, "Dao"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;
import tk.mybatis.mapper.common.Mapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import java.util.List;
import com.github.pagehelper.Page;
/**
* $!{tableInfo.comment}($!{entityName})表数据库访问层
*
* @author $!author
* @since $!time.currTime()
*/
public interface $!{tableName} extends Mapper<$!{entityName}> {
}
三、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;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务接口
*
* @author $!author
* @since $!time.currTime()
*/
public interface $!{tableInfo.name}Service {
}
四、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}.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.dao.$!{tableInfo.name}Dao;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
*
* @author $!author
* @since $!time.currTime()
*/
@Service
public class $!{tableName} implements $!{tableInfo.name}Service {
@Autowired
private ${tableInfo.name}Dao $!tool.firstLowerCase($tableInfo.name)Dao;
}
五、controller层模板
##定义初始变量
#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.web.bind.annotation.*;
import com.alibaba.dubbo.config.annotation.Reference;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表控制层
*
* @author $!author
* @since $!time.currTime()
*/
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
/**
* 服务对象
*/
@Reference
private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
}
六、mapper.xml
##引入mybatis支持
$!mybatisSupport
##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources/com/ysh/dao"))
##拿到主键
#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}.dao.$!{tableInfo.name}Dao">
<resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
<result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
</resultMap>
</mapper>
标签:dubbo,name,tableInfo,##,tool,EasyCode,import,append,mapper 来源: https://www.cnblogs.com/lxs1204/p/14208220.html