EasyCode tk.mybatis swagger mysql 通用模板

1.实体类

##引入宏定义
$!define
#set($entityName = $tableInfo.name.substring(1))
##使用宏定义设置回调(保存位置与文件后缀)
#save("/entity", ".java")
$!callback.setFileName($tool.append($entityName, ".java"))
##使用宏定义设置包后缀
#setPackageSuffix("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 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.fullColumn)
    #if(${column.comment})/**
    * ${column.comment}
    */#end
    @Column(name = "$column.obj.name")
    @ApiModelProperty(value = "${column.comment}")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end

}

2.mapper

##定义初始变量
#set($entityName = $tableInfo.name.substring(1))
#set($tableName = $tool.append($entityName, "Mapper"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper"))


#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mapper;
import tk.mybatis.mapper.common.BaseMapper;
import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name.substring(1)};
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

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

3.service

##定义初始变量
#set($entityName = $tableInfo.name.substring(1))
#set($tableName = $tool.append($entityName, "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 org.springframework.beans.factory.annotation.Autowired;
import com.zjf.fmall.mapper.$!{entityName}Mapper
import org.springframework.stereotype.Service;
import $!{tableInfo.savePackageName}.entity.$!{entityName};
import java.util.List;
import java.time.LocalDateTime;

/**
 * $!{tableInfo.comment}($!{entityName})表服务接口
 *
 * @author $!author
 * @since $!time.currTime()
 */
@Service
public class $!{tableName} {
    @Autowired
    private $!{entityName}Mapper $!tool.firstLowerCase($entityName)Mapper;

    /**
     * 插入$!{tableInfo.comment}
     *
     * @param $!tool.firstLowerCase($entityName) $!{tableInfo.comment}
     * @return {@link JsonResult}
     */
    public JsonResult insert($!{entityName} $!tool.firstLowerCase($entityName)){
        $!{tool.firstLowerCase($entityName)}.setId(StringUtil.getUUID());
        $!{tool.firstLowerCase($entityName)}Mapper.insertSelective($!tool.firstLowerCase($entityName));
        return JsonResult.success();
    }

    /**
     * 更新$!{tableInfo.comment}
     *
     * @param $!tool.firstLowerCase($entityName) $!{tableInfo.comment}
     * @return {@link JsonResult}
     */
    public JsonResult update($!{entityName} $!tool.firstLowerCase($entityName)){
        $!{tool.firstLowerCase($entityName)}.setUpdateTime(LocalDateTime.now());
        $!{tool.firstLowerCase($entityName)}Mapper.updateByPrimaryKeySelective($!tool.firstLowerCase($entityName));
        return JsonResult.success();
    }

    /**
     * 删除$!{tableInfo.comment}
     *
     * @param id 编号
     * @return {@link JsonResult}
     */
    public JsonResult remove(String id){
        $!{tool.firstLowerCase($entityName)}Mapper.deleteByPrimaryKey(id);
        return JsonResult.success();
    }

    /**
     * 查询一条
     *
     * @param  $!tool.firstLowerCase($entityName) $!{tableInfo.comment}
     * @return {@link JsonResult}
     */
    public JsonResult findOne($!{entityName} $!tool.firstLowerCase($entityName)){
        return JsonResult.success($!{tool.firstLowerCase($entityName)}Mapper.selectOne($!tool.firstLowerCase($entityName)));
    }
}

4.controller

##定义初始变量
#set($tableName = $tool.append($tableInfo.name.substring(1), "Controller"))
#set($entityName = $tableInfo.name.substring(1))
##设置回调
$!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 org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * $!{tableInfo.comment}($!{entityName})表控制层
 *
 * @author $!author
 * @since $!time.currTime()
 */
@RestController
@RequestMapping("$!tool.firstLowerCase($entityName)")
public class $!{tableName} {
    /**
     * 服务对象
     */
    @Autowired
    private $!{entityName}Service $!tool.firstLowerCase($entityName)Service;


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值