其他分享
首页 > 其他分享> > 使用EasyCode(代码神器)生成代码-自定义模板

使用EasyCode(代码神器)生成代码-自定义模板

作者:互联网

自定义模版

File->Settings->Easy Code->Template Setting:

entity.java

##引入宏定义
$!define

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

##使用宏定义设置包后缀
#setPackageSuffix("entity")

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

import com.baomidou.mybatisplus.annotation.TableName;
import com.mst.core.page.Pagination;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

import java.util.Date;

##使用宏定义实现类注释信息
#tableComment("实体类")
@TableName("$!{tableInfo.obj.name}")
@Data
public class $!{tableInfo.name} extends Pagination implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})

    /**
     * ${column.comment}
     */#end
	
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
 
}

dao.java

##定义初始变量
#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;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
 *
 * @author $!作者名
 * @since $!time.currTime()
 */
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}> {
 
}

service.java

##定义初始变量
#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 $!作者名
 * @since $!time.currTime()
 */
public interface $!{tableName} extends IService<$!{tableInfo.name}>{
 
}

ServiceImpl.java

##定义初始变量
#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}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
 
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
 *
 * @author $!作者名
 * @since $!time.currTime()
 */
@Service
@Slf4j
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {
  
}

controller.java

##定义初始变量
#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 com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mst.core.result.CommonResult;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author $!作者名
 * @since $!time.currTime()
 */
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
@Api(tags = "$tableInfo.name")
@Slf4j
public class $!{tableName} {
 
    /**
     * 服务对象
     */
    @Autowired
    private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
  
    /**
     * @Function: 
     * @Date: $!time.currTime()
     * @param: []
     * @return: 
     * @deprecated 添加信息
     */
    @PostMapping("save")
    @ApiOperation(value = "添加信息")
    public Boolean save($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.save($!tool.firstLowerCase($tableInfo.name));
    }
	
    /**
     * @Function: 
     * @Date: $!time.currTime()
     * @param: id
     * @return: 
     * @deprecated 根据id删除信息
     */
    @PostMapping("delete")
    @ApiOperation(value = "根据id删除信息")
    public Boolean delete(Long id) {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.removeById(id);
    }
	
    /**
     * @Function: 
     * @Date: $!time.currTime()
     * @param: [idList]
     * @return: 
     * @deprecated 批量删除
     */
    @PostMapping("batchDel")
    @ApiOperation(value = "批量删除")
    public Boolean batchDel(String ids) {
		List<String> idList = Arrays.asList(ids.split(","));
        return $!{tool.firstLowerCase($tableInfo.name)}Service.removeByIds(idList);
    }
	
    /**
     * @Function: 
     * @Date: $!time.currTime()
     * @param: [$!tool.firstLowerCase($tableInfo.name)]
     * @return: 
     * @deprecated 更新信息
     */
    @PostMapping("renew")
    @ApiOperation(value = "更新信息")
    public Boolean renew($!{tableInfo.name} $!tool.firstLowerCase($tableInfo.name)) {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.updateById($!tool.firstLowerCase($tableInfo.name));
    }
 
    /**
     * @Function: 
     * @Date: $!time.currTime()
     * @param: []
     * @return: 
     * @deprecated 根据id查询单个详情
     */
	@PostMapping("/query")
    @ApiOperation(value = "根据id查询单个详情")
    public $!{tableInfo.name} query(Long id) {
        return $!{tool.firstLowerCase($tableInfo.name)}Service.getById(id);
    }

    /**
     * @Function: 
     * @Date: $!time.currTime()
     * @param: []
     * @return: 
     * @deprecated 查询所有数据
     */
	@PostMapping("/list")
    @ApiOperation(value = "查询所有数据")
    public IPage list($!{tableInfo.name} entity) {
		LambdaQueryWrapper<$!{tableInfo.name}> queryWrapper = new LambdaQueryWrapper<>();
        // queryWrapper.like(StudyCircles::getTitle,""); // 模糊查询
        IPage<$!{tableInfo.name}> page = $!{tool.firstLowerCase($tableInfo.name)}Service.page(new Page(entity.getPageIndex(), entity.getPageSize()), queryWrapper);
        return page;
    }

}

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">
 
</mapper>

 

标签:tableInfo,name,自定义,savePackageName,##,代码,EasyCode,import,tool
来源: https://blog.csdn.net/xiaozhu2623/article/details/116994821