easycode 插件生成

模板 d100ca7639f894d3f948d39be395b88b

 entity

##导入宏定义
$!define
##保存文件(宏定义)
#save("/entity", ".java")
##包路径(宏定义)
#setPackageSuffix("entity")
##自动导入包(全局变量)
$!autoImport
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;


##表注释(宏定义)
#tableComment("表实体类")
@Data
@ApiModel("$!{tableInfo.comment}")
public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> implements Serializable {

private static final long serialVersionUID = $!tool.serial();

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
    #if($column.name.equals('id'))@TableId(type = IdType.AUTO)#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}
service

##导入宏定义
$!define

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

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

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

import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
import $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import $!{tableInfo.savePackageName}.common.*;
import $!{tableInfo.savePackageName}.param.*;
import $!{tableInfo.savePackageName}.dto.*;
import $!{tableInfo.savePackageName}.vo.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import java.io.Serializable;
import java.util.*;

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

    public $!{tableInfo.name}ListVo list($!{tableInfo.name}ListParam param) {
        $!{tableInfo.name}ListVo vo = new $!{tableInfo.name}ListVo(true, "查询成功");
        QueryWrapper<$!{tableInfo.name}> wrapper = new QueryWrapper<>();
        wrapper.lambda()
                .eq(ObjectUtils.isNotEmpty(param.getStatus()), $!{tableInfo.name}::getStatus, param.getStatus())
                .in(CollectionUtils.isNotEmpty(param.getIdList()), $!{tableInfo.name}::getId, param.getIdList())
                .ge(ObjectUtils.isNotEmpty(param.getStartCreateTime()), $!{tableInfo.name}::getCreateTime, param.getStartCreateTime())
                .le(ObjectUtils.isNotEmpty(param.getEndCreateTime()), $!{tableInfo.name}::getCreateTime, param.getEndCreateTime())
                .orderByDesc($!{tableInfo.name}::getCreateTime);
        PageHelper.startPage(param.getCurrentPage(), param.getPageSize());
        List<$!{tableInfo.name}> list = this.list(wrapper);
        List<$!{tableInfo.name}Dto> dtoList = new ArrayList<>();
        for ($!{tableInfo.name} $!tool.firstLowerCase($!tableInfo.name) : list){
            $!{tableInfo.name}Dto dto= new $!{tableInfo.name}Dto();
            BeanUtils.copyProperties($!tool.firstLowerCase($!tableInfo.name),dto);
            dtoList.add(dto);
        }
        vo.setList(dtoList);
        PageInfo<$!{tableInfo.name}> pageInfo = new PageInfo<>(list);
        vo.setTotal(pageInfo.getTotal());
        vo.setPageSize(param.getPageSize());
        vo.setCurrentPage(param.getCurrentPage());
        return vo;
    }
    
     public $!{tableInfo.name}Vo get(Serializable id) {
       $!{tableInfo.name}Vo vo = new $!{tableInfo.name}Vo(true, "查询成功");
       $!{tableInfo.name} $!tool.firstLowerCase($!tableInfo.name) = this.getById(id);
       $!{tableInfo.name}Dto dto = new  $!{tableInfo.name}Dto();
       BeanUtils.copyProperties($!tool.firstLowerCase($!tableInfo.name), dto);
       vo.setData(dto);
       return vo;
    }
    
    public ResultDto save($!{tableInfo.name}SaveParam param) {
        ResultDto dto = new ResultDto(true, "保存成功");
        $!{tableInfo.name} $!tool.firstLowerCase($!tableInfo.name) = new $!{tableInfo.name}();
        BeanUtils.copyProperties(param, $!tool.firstLowerCase($!tableInfo.name));
        this.save($!tool.firstLowerCase($!tableInfo.name));
        return dto;
    }

    public ResultDto update($!{tableInfo.name}UpdateParam param) {
        ResultDto dto = new ResultDto(true, "更新成功");
        $!{tableInfo.name} $!tool.firstLowerCase($!tableInfo.name) = new $!{tableInfo.name}();
        BeanUtils.copyProperties(param, $!tool.firstLowerCase($!tableInfo.name));
        UpdateWrapper<$!{tableInfo.name}> wrapper = new UpdateWrapper<>();
        wrapper.lambda().in(CollectionUtils.isNotEmpty(param.getIdList()), $!{tableInfo.name}::getId, param.getIdList());
        this.update($!tool.firstLowerCase($!tableInfo.name), wrapper);
        return dto;
    }

    public ResultDto delete(List<Long> idList) {
        ResultDto dto = new ResultDto(true, "删除成功");
        this.removeByIds(idList);
        return dto;
    }
}
controller
##导入宏定义
$!define

##设置表后缀(宏定义)
#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.extension.api.ApiController;
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
import org.springframework.web.bind.annotation.*;
import $!{tableInfo.savePackageName}.common.*;
import $!{tableInfo.savePackageName}.param.*;
import $!{tableInfo.savePackageName}.vo.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

##表注释(宏定义)
#tableComment("表控制层")
@RestController
@RequestMapping("/$!tool.firstLowerCase($!tableInfo.name)/")
public class $!{tableName} extends ApiController {
  
    @Resource
    private $!{tableInfo.name}Service $!{serviceName};

    @GetMapping("list")
    @ApiOperation(value = "根据条件查询所有数据", notes = "根据条件查询所有数据")
    public $!{tableInfo.name}ListVo list($!{tableInfo.name}ListParam param) {
        return $!{serviceName}.list(param);
    }

    
    @GetMapping("{id}")
    @ApiOperation(value = "通过主键查询单条数据", notes = "通过主键查询单条数据")
    public $!{tableInfo.name}Vo get(@PathVariable Serializable id) {
        return $!{serviceName}.get(id);
    }

    @PostMapping("save")
    @ApiOperation(value = "新增数据", notes = "新增数据")
    public ResultDto save(@RequestBody $!{tableInfo.name}SaveParam $!entityName) {
        return $!{serviceName}.save($!entityName);
    }

   
    @PutMapping("update")
    @ApiOperation(value = "修改数据", notes = "修改数据")
    public ResultDto update(@RequestBody $!{tableInfo.name}UpdateParam $!entityName) {
        return $!{serviceName}.update($!entityName);
    }

    @ApiOperation(value = "删除数据", notes = "删除数据")
    @DeleteMapping("delete")
    public ResultDto delete(@RequestParam("idList") List<Long> idList) {
        return $!{serviceName}.delete(idList);
    }
}
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">

    <resultMap type="$!{tableInfo.savePackageName}.entity.$!{tableInfo.name}" id="$!{tableInfo.name}Map">
#foreach($column in $tableInfo.fullColumn)
        <result property="$!column.name" column="$!column.obj.name" jdbcType="$!column.ext.jdbcType"/>
#end
    </resultMap>
    
 <!--  <sql id="Base_Column_List" >
    #foreach($column in $tableInfo.fullColumn)
     $!column.obj.name, 
    #end
   </sql> -->
</mapper>
mapper
##导入宏定义
$!define

##设置表后缀(宏定义)
#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> {

}
listParam
##导入宏定义
$!define
##保存文件(宏定义)
#save("/param", "ListParam.java")
##包路径(宏定义)
#setPackageSuffix("param")
##自动导入包(全局变量)
$!autoImport
import $!{tableInfo.savePackageName}.common.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;



@Data
@ApiModel("查询参数")
public class $!{tableInfo.name}ListParam extends PageParam {

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}
dto
##导入宏定义
$!define
##保存文件(宏定义)
#save("/dto", "Dto.java")
##包路径(宏定义)
#setPackageSuffix("dto")
##自动导入包(全局变量)
$!autoImport
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;



@Data
@ApiModel("对象返回值")
public class $!{tableInfo.name}Dto {

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end

}
saveParam
##导入宏定义
$!define
##保存文件(宏定义)
#save("/param", "SaveParam.java")
##包路径(宏定义)
#setPackageSuffix("param")
##自动导入包(全局变量)
$!autoImport
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;



@Data
@ApiModel("保存参数")
public class $!{tableInfo.name}SaveParam {

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}
updateParam
##导入宏定义
$!define
##保存文件(宏定义)
#save("/param", "UpdateParam.java")
##包路径(宏定义)
#setPackageSuffix("param")
##自动导入包(全局变量)
$!autoImport
import $!{tableInfo.savePackageName}.common.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;



@Data
@ApiModel("更新参数")
public class $!{tableInfo.name}UpdateParam extends BaseParam {

#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})@ApiModelProperty(value = "${column.comment}")#end
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
    
#end
}
vo
##导入宏定义
$!define
##保存文件(宏定义)
#save("/vo", "Vo.java")
##包路径(宏定义)
#setPackageSuffix("vo")
##自动导入包(全局变量)
$!autoImport
import $!{tableInfo.savePackageName}.common.*;
import $!{tableInfo.savePackageName}.dto.*;
import io.swagger.annotations.ApiModel;
import lombok.Data;



@Data
@ApiModel("对象返回值")
public class $!{tableInfo.name}Vo extends ResultDto {

    private $!{tableInfo.name}Dto data;

    public $!{tableInfo.name}Vo() {
    }

    public $!{tableInfo.name}Vo(Boolean success, String message) {
        super(success, message);
    }
}
listVo
##导入宏定义
$!define
##保存文件(宏定义)
#save("/vo", "ListVo.java")
##包路径(宏定义)
#setPackageSuffix("vo")
##自动导入包(全局变量)
$!autoImport
import $!{tableInfo.savePackageName}.dto.*;
import $!{tableInfo.savePackageName}.common.ListResultDto;
import io.swagger.annotations.ApiModel;
import lombok.Data;



@Data
@ApiModel("列表返回值")
public class $!{tableInfo.name}ListVo extends ListResultDto<$!{tableInfo.name}Dto> {

   public $!{tableInfo.name}ListVo() {
    }

    public $!{tableInfo.name}ListVo(Boolean success, String message) {
        super(success, message);
    }
}

 

common 代码

package com.zhang.common;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.List;

@Data
@ApiModel("BaseParam")
public class BaseParam {
    private List<Integer> idList;

    private String startCreateTime;

    private String endCreateTime;

    private Integer status;
}
package com.zhang.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@ApiModel("ListResultDto")
public class ListResultDto<T> extends ResultDto {

    @ApiModelProperty(value = "总数")
    private Long total = 0L;

    @ApiModelProperty(value = "当前页")
    private Integer currentPage;

    @ApiModelProperty(value = "分页大小")
    private Integer pageSize;

    @ApiModelProperty(value = "列表数据")
    private List<T> list = new ArrayList();

    public ListResultDto() {
    }

    public ListResultDto(Boolean success, String message) {
        super.setMessage(message);
        super.setSuccess(success);
    }

}
package com.zhang.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("PageParam")
public class PageParam  extends BaseParam {
    @ApiModelProperty(value = "当前页")
    private Integer currentPage=1;

    @ApiModelProperty(value = "分页大小")
    private Integer pageSize=20;
}
package com.zhang.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("接口统一处理结果")
public class ResultDto {

    @ApiModelProperty(value = "状态码")
    private String code = "200";

    @ApiModelProperty(value = "结果标识符(true:成功,false:失败)")
    private Boolean success = false;

    @ApiModelProperty(value = "响应信息")
    private String message;

    public ResultDto() {
    }

    public ResultDto(Boolean success, String message) {
        this.success = success;
        this.message = message;
    }

    public void setErrorMessage(String message) {
        this.success = false;
        this.message = message;
    }

    public void setSuccessMessage(String message) {
        this.success = true;
        this.message = message;
    }


}
server:
  port: 8880
  servlet:
    contextPath: /

spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/cloud_disk?useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: Zjr@121847
    druid:
      keep-alive: true
      initial-size: 5
      min-idle: 5
      max-active: 20
      # 配置获取连接等待超时的时间
      max-wait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 300000
      validation-query: SELECT 1 FROM DUAL
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      web-stat-filter:
        enabled: true
        url-pattern: /*
        exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: false
        login-username: admin
        login-password: admin
        allow:
      # 连接泄露检查,打开removeAbandoned功能 , 连接从连接池借出后,长时间不归还,将触发强制回连接。回收周期随timeBetweenEvictionRunsMillis进行,如果连接为从连接池借出状态,并且未执行任何sql,并且从借出时间起已超过removeAbandonedTimeout时间,则强制归还连接到连接池中。
      remove-abandoned: true
      # 超时时间,秒
      remove-abandoned-timeout: 80
      # 关闭abanded连接时输出错误日志,这样出现连接泄露时可以通过错误日志定位忘记关闭连接的位置
      log-abandoned: true
      # 打开PSCache,并且指定每个连接上PSCache的大小
      pool-prepared-statements: true
      max-pool-prepared-statement-per-connection-size: 20
      # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
      filters: stat,wall,slf4j,config
      # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
      connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

  application:
    name: video
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
  profiles:
    active: dev
  servlet:
    multipart:
      max-file-size: 102400000
      max-request-size: 102400000
  web:
    resources:
      static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${web.upload-path}

#Mybatis配置
mybatis:
  configuration:
    map-underscore-to-camel-case: true
    #打印SQL
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  type-aliases-package: com.zhang.entity.**
  mapper-locations: classpath*:mapper/*.xml

#分页插件配置
pagehelper:
  autoRuntimeDialect: true
  # 当该参数设置为 true 时,pageNum<=0 时会查询第一页, pageNum>pages(超过总数时),会查询最后一页.也就是即使传入页数大于总页数,仍然会返回数据
  reasonable: false
  supportMethodsArguments: true
  params: count=countSql

 

 <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- 移除掉默认支持的 Tomcat -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- 添加 Undertow 容器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.10</version>
            <exclusions>
                <exclusion>
                    <groupId>org.mybatis.spring.boot</groupId>
                    <artifactId>mybatis-spring-boot-starter</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <!--Swagger-UI API文档生产工具-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-autoconfigure</artifactId>
            <version>1.3.2</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>

    </dependencies>

 

 

 

posted on 2021-08-31 14:26  zhangjinru123  阅读(228)  评论(0编辑  收藏  举报