本文主要是介绍EasyCode代码生成模板,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前言:
EasyCode是 IDEA 开发的一个代码生成插件,主要通过自定义模板(基于velocity)来生成各种你想要的代码。相信大家都了解EasyCode是干嘛用的,下面是比较简约的一个生成模板,个人比较喜欢。
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 io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;/*** $!{tableInfo.comment}($!{tableInfo.name})表服务控制层** @author yjj* @since $!time.currTime()*/
@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})")
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {@Resource$!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;}
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 com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};/*** $!{tableInfo.comment}($!{tableInfo.name})表服务接口层** @author yjj* @since $!time.currTime()*/
public interface $!{tableInfo.name}Service extends IService<$!{tableInfo.name}>{}
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;##表注释(宏定义)
##tableComment("表服务实现类")
/*** $!{tableInfo.comment}($!{tableInfo.name})表服务实现类** @author yjj* @since $!time.currTime()*/
@Service
public class $!{tableInfo.name}ServiceImpl extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {}
Mapper
##定义初始变量
#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 com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;/*** $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层** @author yjj* @since $!time.currTime()*/
@Mapper
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}>{}
Entity
##引入宏定义
$!{define.vm}##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")##使用宏定义设置包后缀
#setPackageSuffix("entity")##使用全局变量实现默认包导入
$!{autoImport.vm}
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;import java.io.Serializable;##表注释(宏定义)
##tableComment("表实体类")
/*** $!{tableInfo.comment}($!{tableInfo.name})表实体类* * @author yjj* @since $!time.currTime()*/
@Data
@ApiModel(description = "")
@SuppressWarnings("serial")
public class $!{tableInfo.name} implements Serializable {private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)##if(${column.comment})/**##* ${column.comment}##*/#end@ApiModelProperty("$column.comment")private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
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<?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}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)<result property="$!column.name" column="$!column.obj.name"/>
#end</resultMap></mapper>
这篇关于EasyCode代码生成模板的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!