easyCode自定義Mybatisplus模板

1、entity

##引入宏定義
$!define

##使用宏定義設置回調(保存位置與文件後綴)
#save("/entity", ".java")

##使用宏定義設置包後綴
#setPackageSuffix("entity")

##使用全局變量實現默認包導入
$!autoImport
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.Data;
import java.io.Serializable;

##使用宏定義實現類註釋信息
###tableComment("實體類")
/**
 * @author $!author
 * @since $!time.currTime()
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class $!{tableInfo.name} extends Model {
    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
## 使用swagger註釋即可,這裏不用再使用文檔註釋了,別的情況請根據需要調整
##    #if(${column.comment})/**
##    * ${column.comment}
##    */#end
    
    @TableField("$column.name")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end

## 因爲使用了lombok,所以去掉get和set方法的生成
###foreach($column in $tableInfo.fullColumn)
####使用宏定義實現get,set方法
###getSetMethod($column)
###end
}

2、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}.entity.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


/**
 * @author $!author
 * @since $!time.currTime()
 */
@Api(tags = "$!{tableInfo.comment}($!{tableInfo.name})") 
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
public class $!{tableName} {
    @Autowired
    private  $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;

}

3、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 com.bonade.hatch.entity.$!{tableInfo.name};


/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服務實現類
 *
 * @author $!author
 * @since $!time.currTime()
 */
public interface $!{tableName} extends IService<$!{tableInfo.name}> {
}

4、serviceImpl

##定義初始變量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
#set($serviceName = $tool.append($tableInfo.name, "Service"))
##設置回調
$!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}.mapper.$!{tableInfo.name}Mapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonade.hatch.service.$!{serviceName};
import org.springframework.stereotype.Service;

/**
 * $!{tableInfo.comment}($!{tableInfo.name})表服務實現類
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{serviceName} {
    
}

5、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 $!author
 * @since $!time.currTime()
 */
 @Mapper
public interface $!{tableName} extends BaseMapper<$!{tableInfo.name}>{

}

6、mapper.xml

##引入mybatis支持
$!mybatisSupport

##設置保存名稱與保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Dao.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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章