当前位置: 首页 > article >正文

easyCode代码模板配置

首先idea按着easycode

在这里插入图片描述

pom.xml项目添加mybatisplus和lombok依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
<!--            <version>1.18.12</version>-->
        </dependency>

使用idea链接数据库配置

在这里插入图片描述

右键可以创建模板或者使用默认模板,以下方法是创建自定义模板使用

在这里插入图片描述

controller.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Controller")

##保存文件(宏定义)
#save("/controller", "Controller.java")

##包路径(宏定义)
#setPackageSuffix("controller")

##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))

##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.http.ResponseEntity;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

##表注释(宏定义)
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author xqf
 * @since $!time.currTime()
 */
@Slf4j
@Api(tags="$!{tableInfo.comment}")
@RestController
@RequestMapping("$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableName}{
    /**
     * 服务对象
     */
    @Resource
    private $!{tableInfo.name}Service $!{serviceName};

    /**
     * 分页查询所有数据
     *
     * @param page 分页对象
     * @param $!entityName 查询实体
     * @return 所有数据
     */
    @ApiOperation(value="$!{tableInfo.comment}-分页对象", notes="$!{tableInfo.comment}-分页对象")
    @GetMapping
    public ResponseEntity selectAll(Page<$!tableInfo.name> page, $!tableInfo.name $!entityName) {
        return ResponseEntity.ok($!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value="$!{tableInfo.comment}-通过主键查询单条数据", notes="$!{tableInfo.comment}-通过主键查询单条数据")
    @GetMapping("{id}")
    public ResponseEntity selectOne(@PathVariable Serializable id) {
        return ResponseEntity.ok($!{serviceName}.getById(id));
    }

    /**
     * 新增数据
     *
     * @param $!entityName 实体对象
     * @return 新增结果
     */
    @ApiOperation(value="$!{tableInfo.comment}-新增数据", notes="$!{tableInfo.comment}-新增数据")
    @PostMapping
    public ResponseEntity insert(@RequestBody $!tableInfo.name $!entityName) {
        return ResponseEntity.ok($!{serviceName}.save($!entityName));
    }

    /**
     * 修改数据
     *
     * @param $!entityName 实体对象
     * @return 修改结果
     */
    @ApiOperation(value="$!{tableInfo.comment}-修改数据", notes="$!{tableInfo.comment}-修改数据")
    @PutMapping
    public ResponseEntity update(@RequestBody $!tableInfo.name $!entityName) {
        return ResponseEntity.ok($!{serviceName}.updateById($!entityName));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation(value="$!{tableInfo.comment}-删除数据", notes="$!{tableInfo.comment}-删除数据")
    @DeleteMapping
    public ResponseEntity delete(@RequestParam("idList") List<Long> idList) {
        return ResponseEntity.ok($!{serviceName}.removeByIds(idList));
    }
}

service.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Service")

##保存文件(宏定义)
#save("/service", "Service.java")

##包路径(宏定义)
#setPackageSuffix("service")

import com.baomidou.mybatisplus.extension.service.IService;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;

##表注释(宏定义)
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author xqf
 * @since $!time.currTime()
 */
#tableComment("表服务接口")
public interface $!{tableName} extends IService<$!tableInfo.name> {

}

serviceImpl.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("ServiceImpl")

##保存文件(宏定义)
#save("/service/impl", "ServiceImpl.java")

##包路径(宏定义)
#setPackageSuffix("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;

##表注释(宏定义)
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author xqf
 * @since $!time.currTime()
 */
#tableComment("表服务实现类")
@Service
public class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {

}

entity.java.vm

##引入宏定义
$!{define.vm}

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

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

##使用全局变量实现默认包导入
$!{autoImport.vm}
import java.io.Serializable;

##使用宏定义实现类注释信息
#tableComment("实体类")
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author xqf
 * @since $!time.currTime()
 */
@Data
@TableName("$!{tableInfo.obj.name}")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="$!{tableInfo.comment}对象", description="$!{tableInfo.comment}")
public class $!{tableInfo.name} implements Serializable {
    private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/**
     * ${column.comment}
     */#end
    #if($column.type =='java.util.Date')
    
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")#end
    
    @ApiModelProperty(value = "$!{column.comment}")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end

}

mapper.java.vm

##导入宏定义
$!{define.vm}

##设置表后缀(宏定义)
#setTableSuffix("Mapper")

##保存文件(宏定义)
#save("/mapper", "Mapper.java")

##包路径(宏定义)
#setPackageSuffix("mapper")

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;

##表注释(宏定义)
/**
 * $!{tableInfo.comment}($!{tableInfo.name})表控制层
 *
 * @author xqf
 * @since $!time.currTime()
 */
#tableComment("表数据库访问层")
public interface $!{tableName} extends BaseMapper<$!tableInfo.name> {

}

mapper.xml.vm

##引入mybatis支持
$!{mybatisSupport.vm}

##设置保存名称与保存位置
$!callback.setFileName($tool.append($!{tableInfo.name}, "Mapper.xml"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mapper/xml"))

##拿到主键
#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>

直接创建例子

在这里插入图片描述

选择自己定义的模板(可以根据不同框架自定模板)

在这里插入图片描述


http://www.kler.cn/a/548760.html

相关文章:

  • Mybatisplus自定义sql
  • 双指针-三数之和
  • 机器视觉--switch语句
  • 海尔小红书年度规划方案拆解
  • 使用 Ansys Fluent 进行电池热滥用失控传播仿真
  • 使用 Ansys MotorCAD 进行轴向磁通电机设计
  • Python的imutils库详细介绍
  • 详解tensorflow的tensor和Python list及Numpy矩阵的区别
  • Day7 微服务 Elasticsearch搜索引擎、DSL查询(叶子查询、复合查询、排序、分页、高亮)、RestClient查询、数据聚合
  • 网络安全学习笔记
  • 二十九、vite项目集成webpack+vue2项目
  • 深蓝学院自主泊车第2次作业-EKF
  • Vue 4.0发布!JSX vs 模板语法:谁才是前端的未来?
  • 线性表之顺序表
  • 【2025最新计算机毕业设计】基于SpringBoot+Vue高校社团管理系统 【提供源码+答辩PPT+文档+项目部署】
  • DeepSeek专题:以专业角度详细讲讲Deepseek-R1的高质量数据合成过程⌛
  • 机试刷题_字符串的排列【python】
  • 容器运行常见数据库
  • python电影数据分析及可视化系统建设
  • 深入学习Linux命令行中的各种替换操作(命令替换、参数替换、进程替换)