easycode template (for personal use)

controller

##导入宏定义
$!{
    
    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 $!{
    
    tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{
    
    tableInfo.savePackageName}.service.$!{
    
    tableInfo.name}Service;
import org.zzd.utils.PageHelper;
import org.zzd.exception.ResponseException;
import org.zzd.result.ResultCodeEnum;
import org.zzd.result.ResponseResult;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

##表注释(宏定义)
#tableComment("表控制层")
@Api(tags = "")
@RestController
@RequestMapping("/api/$!tool.firstLowerCase($!tableInfo.name)")
public class $!{
    
    tableName} {
    
    

    @Autowired
    private $!{
    
    tableInfo.name}Service $!{
    
    serviceName};

    @ApiOperation(value = "分页查询")
    @PostMapping("/queryPage")
    @ApiImplicitParams({
    
    
            @ApiImplicitParam(name = "pageNum", value = "当前页", paramType = "query", dataType = "integer",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", paramType = "query", dataType = "integer",defaultValue = "10"),
            @ApiImplicitParam(name = "startCreateTime", value = "起始日期", paramType = "query", dataType = "date"),
            @ApiImplicitParam(name = "endCreateTime", value = "结束日期", paramType = "query", dataType = "date")
    })
    public ResponseResult<PageHelper<$!{
    
    tableInfo.name}>> queryPage(@ApiIgnore @RequestParam HashMap params) {
    
    
        return $!{
    
    serviceName}.queryPage(params);
    }

    @ApiOperation(value = "获取详情")
    @GetMapping("/read")
    public ResponseResult selectOne(Integer id) {
    
    
        $!tableInfo.name $!entityName = $!{
    
    serviceName}.getById(id);
        if (!Objects.isNull($!entityName)) {
    
    
            return ResponseResult.success($!entityName);
        }
        else {
    
    
            throw new ResponseException(ResultCodeEnum.PARAM_NOT_VALID.getCode(), ResultCodeEnum.PARAM_NOT_VALID.getMessage());
        }
    }

    @ApiOperation(value = "新增数据")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody $!tableInfo.name $!entityName) {
    
    
        boolean flag = $!{
    
    serviceName}.save($!entityName);
        if (flag) {
    
    
            return ResponseResult.success();
        }else {
    
    
            throw new ResponseException(ResultCodeEnum.DATA_ERROR.getCode(), ResultCodeEnum.DATA_ERROR.getMessage());
        }
    }

    @ApiOperation(value = "修改数据")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody $!tableInfo.name $!entityName) {
    
    
        $!{
    
    serviceName}.updateById($!entityName);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping("delete")
    public ResponseResult delete(Long id) {
    
    
        boolean flag = $!{
    
    serviceName}.removeById(id);
        if (flag) {
    
    
            return ResponseResult.success();
        }
        else {
    
    
            throw new ResponseException(ResultCodeEnum.PARAM_NOT_VALID.getCode(), ResultCodeEnum.PARAM_NOT_VALID.getMessage());
        }
    }
    @ApiOperation(value = "批量删除数据")
    @DeleteMapping("/batchRemove")
    public ResponseResult batchRemove(@RequestBody List<Long> idList) {
    
    
        $!{
    
    serviceName}.removeByIds(idList);
        return ResponseResult.success();
    }
}

mapper

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

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

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

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

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

##表注释(宏定义)
#tableComment("表数据库访问层")
public interface $!{
    
    tableName} extends BaseMapper<$!tableInfo.name> {
    
    

}

entity

##导入宏定义
$!{
    
    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 $!{
    
    tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{
    
    tableInfo.savePackageName}.service.$!{
    
    tableInfo.name}Service;
import org.zzd.utils.PageHelper;
import org.zzd.exception.ResponseException;
import org.zzd.result.ResultCodeEnum;
import org.zzd.result.ResponseResult;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

##表注释(宏定义)
#tableComment("表控制层")
@Api(tags = "")
@RestController
@RequestMapping("/api/$!tool.firstLowerCase($!tableInfo.name)")
public class $!{
    
    tableName} {
    
    

    @Autowired
    private $!{
    
    tableInfo.name}Service $!{
    
    serviceName};

    @ApiOperation(value = "分页查询")
    @PostMapping("/queryPage")
    @ApiImplicitParams({
    
    
            @ApiImplicitParam(name = "pageNum", value = "当前页", paramType = "query", dataType = "integer",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", paramType = "query", dataType = "integer",defaultValue = "10"),
            @ApiImplicitParam(name = "startCreateTime", value = "起始日期", paramType = "query", dataType = "date"),
            @ApiImplicitParam(name = "endCreateTime", value = "结束日期", paramType = "query", dataType = "date")
    })
    public ResponseResult<PageHelper<$!{
    
    tableInfo.name}>> queryPage(@ApiIgnore @RequestParam HashMap params) {
    
    
        return $!{
    
    serviceName}.queryPage(params);
    }

    @ApiOperation(value = "获取详情")
    @GetMapping("/read")
    public ResponseResult selectOne(Integer id) {
    
    
        $!tableInfo.name $!entityName = $!{
    
    serviceName}.getById(id);
        if (!Objects.isNull($!entityName)) {
    
    
            return ResponseResult.success($!entityName);
        }
        else {
    
    
            throw new ResponseException(ResultCodeEnum.PARAM_NOT_VALID.getCode(), ResultCodeEnum.PARAM_NOT_VALID.getMessage());
        }
    }

    @ApiOperation(value = "新增数据")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody $!tableInfo.name $!entityName) {
    
    
        boolean flag = $!{
    
    serviceName}.save($!entityName);
        if (flag) {
    
    
            return ResponseResult.success();
        }else {
    
    
            throw new ResponseException(ResultCodeEnum.DATA_ERROR.getCode(), ResultCodeEnum.DATA_ERROR.getMessage());
        }
    }

    @ApiOperation(value = "修改数据")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody $!tableInfo.name $!entityName) {
    
    
        $!{
    
    serviceName}.updateById($!entityName);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping("delete")
    public ResponseResult delete(Long id) {
    
    
        boolean flag = $!{
    
    serviceName}.removeById(id);
        if (flag) {
    
    
            return ResponseResult.success();
        }
        else {
    
    
            throw new ResponseException(ResultCodeEnum.PARAM_NOT_VALID.getCode(), ResultCodeEnum.PARAM_NOT_VALID.getMessage());
        }
    }
    @ApiOperation(value = "批量删除数据")
    @DeleteMapping("/batchRemove")
    public ResponseResult batchRemove(@RequestBody List<Long> idList) {
    
    
        $!{
    
    serviceName}.removeByIds(idList);
        return ResponseResult.success();
    }
}

service

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

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

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

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

import com.baomidou.mybatisplus.extension.service.IService;
import $!{
    
    tableInfo.savePackageName}.entity.$!tableInfo.name;
import org.zzd.result.ResponseResult;
import org.zzd.utils.PageHelper;

import java.util.HashMap;

##表注释(宏定义)
#tableComment("表服务接口")
public interface $!{
    
    tableName} extends IService<$!tableInfo.name> {
    
    
    // 分页查询
    ResponseResult<PageHelper<$!{
    
    tableInfo.name}>> queryPage(HashMap params);
}

serviceimpl

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

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

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

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

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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.zzd.constant.PageConstant;
import org.zzd.result.ResponseResult;
import org.zzd.utils.PageHelper;
import $!{
    
    tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{
    
    tableInfo.savePackageName}.service.$!{
    
    tableInfo.name}Service;
import $!{
    
    tableInfo.savePackageName}.mapper.$!{
    
    tableInfo.name}Mapper;

import org.springframework.stereotype.Service;

import java.util.HashMap;

##表注释(宏定义)
#tableComment("表服务实现类")
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
public class $!{
    
    tableName} extends ServiceImpl<$!{
    
    tableInfo.name}Mapper, $!{
    
    tableInfo.name}> implements $!{
    
    tableInfo.name}Service {
    
    

    @Override
    public ResponseResult<PageHelper<$!{
    
    tableInfo.name}>> queryPage(HashMap params) {
    
    
        int pageNum = Integer.parseInt((String) params.get(PageConstant.PAGE_NUM));
        int pageSize = Integer.parseInt((String) params.get(PageConstant.PAGE_SIZE));
        Page<$!{
    
    tableInfo.name}> page = new Page(pageNum, pageSize);

        LambdaQueryWrapper<$!{
    
    tableInfo.name}> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        // 起始日期
        if(!StringUtils.isBlank((CharSequence) params.get("startCreateTime"))){
    
    
            lambdaQueryWrapper.ge($!{
    
    tableInfo.name}::getCreateTime,params.get("startCreateTime"));
        }
        // 结束日期
        if(!StringUtils.isBlank((CharSequence) params.get("endCreateTime"))){
    
    
            lambdaQueryWrapper.le($!{
    
    tableInfo.name}::getCreateTime,params.get("endCreateTime"));
        }

        IPage<$!{
    
    tableInfo.name}> iPage = this.page(page, lambdaQueryWrapper);
        return ResponseResult.success(PageHelper.restPage(iPage));
    }
}

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>

Guess you like

Origin blog.csdn.net/shgzzd/article/details/129657165