写在前面(有点啰嗦)
博主在上手springboot后发现项目中有众多重复的部分,为减少工作量(偷懒)就上网搜索是否存在工具可以帮助完成,没想到还真有一个神奇插件,名为easycode,可在idea中下载安装。
继续搜索使用教程后发现一篇宝藏文章: EasyCode的Mybatis终极版模板
点进该博主的主页,发现他发过好几篇文章详细讲解了easycode的使用,本人一一浏览后收获颇丰,在此特别感谢🙏,唯一的难点是上手实操后发现该博主的模板似乎只支持springboot2的项目,检查后发现是因为springboot3中默认不再支持javax(现已改名Jakarta),而swagger2等依赖会默认使用javax而报错,故本人在这位博主的基础上修改了模板内容,使其适用springboot3项目(注意:本篇文章模板只支持springboot3的项目,不支持springboot2的项目)
1.模板分享
话不多说,直接上模板,已经有经验的朋友就看这里就可以了,还没经验的可以扫一眼目录后点击连接跳转至目录 2. 使用教程(包教包会) 😋
1.1 maven添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-3-starter</artifactId>
<version>1.2.21</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
1.2 mvc及sql模板
controller.java.vm(控制层,这里写接口)
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Controller"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/controller"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mvc.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.util.R;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表控制层
*
* @author $!author
* @since $!time.currTime()
*/
@Slf4j
@RestController
@RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
@Tag(name = "$!{tableInfo.comment}($!{tableInfo.name})表控制层")
public class $!{tableName} {
/**
* 服务对象
*/
@Resource
private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
/**
* 全查询
*
* @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
* @return 查询结果
*/
@Operation(summary = "全查询")
@GetMapping
public R queryAll(@Parameter(name = "$!{tool.firstLowerCase($tableInfo.name)} 筛选条件") $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
return $!{tool.firstLowerCase($tableInfo.name)}Service.queryAll($!{tool.firstLowerCase($tableInfo.name)});
}
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@Operation(summary = "通过主键查询单条数据")
@GetMapping("{id}")
public R queryById(@PathVariable("id") $!pk.shortType id) {
return $!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id);
}
/**
* 新增数据
*
* @param $!{tool.firstLowerCase($tableInfo.name)} 实体
* @return 新增结果
*/
@Operation(summary = "新增数据")
@PostMapping
public R add(@Parameter(name = "$!{tool.firstLowerCase($tableInfo.name)} 实体") @RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
return $!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)});
}
/**
* 编辑数据
*
* @param $!{tool.firstLowerCase($tableInfo.name)} 实体
* @return 编辑结果
*/
@Operation(summary = "编辑数据")
@PutMapping
public R edit(@Parameter(name = "$!{tool.firstLowerCase($tableInfo.name)} 实体") @RequestBody $!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
return $!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)});
}
/**
* 删除数据
*
* @param id 主键
* @return 删除是否成功
*/
@Operation(summary = "删除数据")
@DeleteMapping
public R deleteById(@Parameter(name = "id 主键") $!pk.shortType id) {
return $!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id);
}
}
domain.java.vm(实体层,这里放数据实体)
##引入宏定义
$!{define.vm}
##使用宏定义设置回调(保存位置与文件后缀)
#save("/mvc/domain", ".java")
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.domain;
import lombok.extern.slf4j.Slf4j;
import io.swagger.v3.oas.annotations.media.Schema
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.sql.Date;
##使用宏定义实现类注释信息
#tableComment("实体类")
@Slf4j
@Data
@AllArgsConstructor
@NoArgsConstructor
@Schema(name = "$!{tableInfo.comment}($!{tableInfo.name})实体类")
public class $!{tableInfo.name} implements Serializable {
@Serial
private static final long serialVersionUID = $!tool.serial();
#foreach($column in $tableInfo.fullColumn)
#if(${column.comment})/**${column.comment}*/#end
@Schema(#if(${column.comment})description = "${column.comment}"#end)
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}
mapper.java.vm(数据持久层,这里实现持久化操作)
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Mapper"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/mapper"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.mapper;
import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表数据库访问层
*
* @author $!author
* @since $!time.currTime()
*/
@Mapper
public interface $!{tableName} {
/**
* 通过ID查询单条数据
*
* @param $!pk.name 主键
* @return 实例对象
*/
$!{tableInfo.name} queryById($!pk.shortType $!pk.name);
/**
* 查询指定行数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件
* @return 对象列表
*/
List<$!{tableInfo.name}> queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 统计总行数
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 查询条件
* @return 总行数
*/
long count($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 新增数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 影响行数
*/
int insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<$!{tableInfo.name}> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<$!{tableInfo.name}> entities);
/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<$!{tableInfo.name}> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<$!{tableInfo.name}> entities);
/**
* 修改数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 影响行数
*/
int update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 通过主键删除数据
*
* @param $!pk.name 主键
* @return 影响行数
*/
int deleteById($!pk.shortType $!pk.name);
}
service.java.vm(业务逻辑层,这里写业务接口)
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "Service"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/service"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.service;
import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.util.R;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务接口
*
* @author $!author
* @since $!time.currTime()
*/
public interface $!{tableName} {
/**
* 通过ID查询单条数据
*
* @param $!pk.name 主键
* @return 实例对象
*/
R queryById($!pk.shortType $!pk.name);
/**
* 全查询
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 筛选条件
* @return 查询结果
*/
R queryAll($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 新增数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
R insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 修改数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
R update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name}));
/**
* 通过主键删除数据
*
* @param $!pk.name 主键
* @return 是否成功
*/
R deleteById($!pk.shortType $!pk.name);
}
serviceimpl.java.vm(业务实现层,进行业务实际操作)
##定义初始变量
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
##设置回调
$!callback.setFileName($tool.append($tableName, ".java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/mvc/service/impl"))
##拿到主键
#if(!$tableInfo.pkColumn.isEmpty())
#set($pk = $tableInfo.pkColumn.get(0))
#end
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}mvc.service.impl;
import lombok.extern.slf4j.Slf4j;
import $!{tableInfo.savePackageName}.mvc.domain.$!{tableInfo.name};
import $!{tableInfo.savePackageName}.mvc.mapper.$!{tableInfo.name}Mapper;
import $!{tableInfo.savePackageName}.mvc.service.$!{tableInfo.name}Service;
import $!{tableInfo.savePackageName}.util.R;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
/**
* $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
*
* @author $!author
* @since $!time.currTime()
*/
@Slf4j
@Service("$!tool.firstLowerCase($!{tableInfo.name})Service")
public class $!{tableName} implements $!{tableInfo.name}Service {
@Resource
private $!{tableInfo.name}Mapper $!tool.firstLowerCase($!{tableInfo.name})Mapper;
/**
* 通过ID查询单条数据
*
* @param $!pk.name 主键
* @return 实例对象
*/
@Override
public R queryById($!pk.shortType $!pk.name) {
return R.ok().setData($!{tool.firstLowerCase($!{tableInfo.name})}Mapper.queryById($!pk.name));
}
/**
* 全查询
*
* @param $!{tool.firstLowerCase($tableInfo.name)} 筛选条件
* @return 查询结果
*/
@Override
public R queryAll($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
return R.ok().setData($!{tool.firstLowerCase($tableInfo.name)}Mapper.queryAll($!{tool.firstLowerCase($tableInfo.name)}));
}
/**
* 新增数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
@Override
public R insert($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.insert($!tool.firstLowerCase($!{tableInfo.name}));
return R.ok().setData($!tool.firstLowerCase($!{tableInfo.name}));
}
/**
* 修改数据
*
* @param $!tool.firstLowerCase($!{tableInfo.name}) 实例对象
* @return 实例对象
*/
@Override
public R update($!{tableInfo.name} $!tool.firstLowerCase($!{tableInfo.name})) {
this.$!{tool.firstLowerCase($!{tableInfo.name})}Mapper.update($!tool.firstLowerCase($!{tableInfo.name}));
return R.ok().setData(queryById($!{tool.firstLowerCase($!{tableInfo.name})}.get$!tool.firstUpperCase($pk.name)()));
}
/**
* 通过主键删除数据
*
* @param $!pk.name 主键
* @return 是否成功
*/
@Override
public R deleteById($!pk.shortType $!pk.name) {
boolean del = $!{tool.firstLowerCase($!{tableInfo.name})}Mapper.deleteById($!pk.name) > 0;
return R.ok().setData(del);
}
}
mapper.xml.vm(sql的具体语句)
##引入mybatis支持
$!{mybatisSupport.vm}
##设置保存名称与保存位置
$!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}.mvc.mapper.$!{tableInfo.name}Mapper">
<resultMap type="$!{tableInfo.savePackageName}.mvc.domain.$!{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>
<!--查询单个-->
<select id="queryById" resultMap="$!{tableInfo.name}Map">
select
#allSqlColumn()
from $!tableInfo.obj.name
where $!pk.obj.name = #{$!pk.name}
</select>
<!--查询指定行数据-->
<select id="queryAll" resultMap="$!{tableInfo.name}Map">
select
#allSqlColumn()
from $!tableInfo.obj.name
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
and $!column.obj.name = #{$!column.name}
</if>
#end
</where>
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(*)
from $!tableInfo.obj.name
<where>
#foreach($column in $tableInfo.fullColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
and $!column.obj.name = #{$!column.name}
</if>
#end
</where>
</select>
<!--新增所有列-->
<insert id="insert" keyProperty="$!pk.name" useGeneratedKeys="true">
insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values (#foreach($column in $tableInfo.otherColumn)#{$!{column.name}}#if($velocityHasNext), #end#end)
</insert>
<insert id="insertBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values
<foreach collection="entities" item="entity" separator=",">
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
</foreach>
</insert>
<insert id="insertOrUpdateBatch" keyProperty="$!pk.name" useGeneratedKeys="true">
insert into $!{tableInfo.obj.name}(#foreach($column in $tableInfo.otherColumn)$!column.obj.name#if($velocityHasNext), #end#end)
values
<foreach collection="entities" item="entity" separator=",">
(#foreach($column in $tableInfo.otherColumn)#{entity.$!{column.name}}#if($velocityHasNext), #end#end)
</foreach>
on duplicate key update
#foreach($column in $tableInfo.otherColumn)$!column.obj.name = values($!column.obj.name)#if($velocityHasNext),
#end#end
</insert>
<!--通过主键修改数据-->
<update id="update">
update $!{tableInfo.obj.name}
<set>
#foreach($column in $tableInfo.otherColumn)
<if test="$!column.name != null#if($column.type.equals("java.lang.String")) and $!column.name != ''#end">
$!column.obj.name = #{$!column.name},
</if>
#end
</set>
where $!pk.obj.name = #{$!pk.name}
</update>
<!--通过主键删除-->
<delete id="deleteById">
delete from $!{tableInfo.obj.name} where $!pk.obj.name = #{$!pk.name}
</delete>
</mapper>
1.3 配置类及通用类模板
swagger.java.vm(swagger3配置类)
##设置回调
$!callback.setFileName($tool.append("SwaggerConfig.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/config"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}config;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Swagger配置
*
* @author $!author
* @since $!time.currTime()
*/
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info()
.title("接口文档标题")
.description("SpringBoot3 集成 Swagger3接口文档")
.version("v1"))
.externalDocs(new ExternalDocumentation()
.description("项目API文档")
.url("/"));
}
}
accessfilter.java.vm(过滤器配置类)
##设置回调
$!callback.setFileName($tool.append("AccessFilter.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/config"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMethod;
import jakarta.servlet.*;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* 提供跨域支持
*
* @author $!author
* @since $!time.currTime()
*/
@Slf4j
@Configuration
public class AccessFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
response.setHeader("Access-Control-Max-Age", "3600");
response.setHeader("Access-Control-Allow-Headers", "*");
// 跨域时会首先发送一个option请求,这里我们给option请求直接返回正常状态
if (request.getMethod().equals(RequestMethod.OPTIONS.name())) {
response.setStatus(HttpStatus.OK.value());
return;
}
chain.doFilter(req, res);
}
@Override
public void destroy() {
}
}
r.java.vm(统一返回实体通用类)
##设置回调
$!callback.setFileName($tool.append("R.java"))
$!callback.setSavePath($tool.append($tableInfo.savePath, "/util"))
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}util;
import lombok.extern.slf4j.Slf4j;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
/**
* 统一返回对象R
*
* @author $!author
* @since $!time.currTime()
*/
@Slf4j
@Data
@Schema(name = "统一返回对象R")
public class R implements Serializable {
@Serial
private static final long serialVersionUID = $!tool.serial();
@Schema(name = "响应编码")
private int code;
@Schema(name = "响应信息")
private String message;
@Schema(name = "响应数据")
private Object data;
/**
* 设置数据
*
* @param data 数据
* @return R
*/
public R setData(Object data) {
this.data = data;
return this;
}
/**
* 操作成功
*
* @return R
*/
public static R ok() {
R r = new R();
r.code = 200;
r.message = "OK";
return r;
}
/**
* 认证授权失败。 包括密钥信息不正确;数字签名错误;授权已超时
*
* @return R
*/
public static R fail() {
R r = new R();
r.code = 401;
r.message = "fail";
return r;
}
/**
* 系统异常
*
* @return R
*/
public static R exp() {
R r = new R();
r.code = 500;
r.message = "exception";
return r;
}
}
1.4 项目配置文件模板
application.yaml.vm(yaml配置文件)
##设置回调
$!callback.setFileName($tool.append("application.yaml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
spring:
profiles:
active: test
application-dev.yaml.vm(yaml配置文件dev版)
##设置回调
$!callback.setFileName($tool.append("application-dev.yaml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
server:
port: 8080
swagger:
enabled: true
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
mvc:
pathmatch:
matching-strategy: ant_path_matcher
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
initial-size: 15
min-idle: 8
max-active: 30
# 配置获取连接等待超时的时间
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
# 打开PSCache,并且指定每个连接上PSCache的大小
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 60
validation-query: SELECT 1 FROM DUAL
url: jdbc:mysql://localhost:3306/study_space
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
# call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
call-setters-on-nulls: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
application-prod.yaml.vm(yaml配置文件prod版)
##设置回调
$!callback.setFileName($tool.append("application-prod.yaml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
server:
port: 8080
swagger:
enabled: false
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
initial-size: 15
min-idle: 8
max-active: 30
# 配置获取连接等待超时的时间
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
# 打开PSCache,并且指定每个连接上PSCache的大小
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 60
validation-query: SELECT 1 FROM DUAL
url: jdbc:mysql://localhost:3306/study_space
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
# call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
call-setters-on-nulls: true
application-test.yaml.vm(yaml配置文件test版)
##设置回调
$!callback.setFileName($tool.append("application-test.yaml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
server:
port: 8080
swagger:
enabled: true
spring:
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
mvc:
pathmatch:
matching-strategy: ant_path_matcher
datasource:
type: com.alibaba.druid.pool.DruidDataSource
druid:
# 下面为连接池的补充设置,应用到上面所有数据源中
# 初始化大小,最小,最大
initial-size: 15
min-idle: 8
max-active: 30
# 配置获取连接等待超时的时间
max-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
# 打开PSCache,并且指定每个连接上PSCache的大小
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 60
validation-query: SELECT 1 FROM DUAL
url: jdbc:mysql://localhost:3306/study_space
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
mapper-locations: classpath:mapper/*.xml
configuration:
# call-setters-on-nulls 参数的作用是查询的某一行某一列为null,是否返回
call-setters-on-nulls: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
banner.txt.vm(banner佛主保佑)
##设置回调
$!callback.setFileName($tool.append("banner.txt"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
${AnsiColor.BRIGHT_GREEN}
// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //
logback.xml.vm(日志)
##设置回调
$!callback.setFileName($tool.append("logback.xml"))
$!callback.setSavePath($tool.append($modulePath, "/src/main/resources"))
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<contextName>logback</contextName>
<!--定义日志文件的存储地址 只可以配置绝对路径 配置相对路径在项目执行时可以起作用 但打成jar包后会失效-->
<property name="LOG_HOME" value="$modulePath/tmp/logs" />
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!--输出错误日志-->
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/error/%d{yyyy-MM-dd}-error.log</FileNamePattern>
<!--日志文件保留天数 -->
<MaxHistory>10</MaxHistory>
</rollingPolicy>
<!-- 日志名称的格式 -->
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30} - %msg%n</pattern>
</encoder>
<!--日志文件最大的大小 -->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--普通日志文件-->
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${LOG_HOME}/%d{yyyy-MM-dd}.log</FileNamePattern>
<!--日志文件保留天数 -->
<MaxHistory>10</MaxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符 -->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{30} - %msg%n</pattern>
</encoder>
<!--日志文件最大的大小 -->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<MaxFileSize>10MB</MaxFileSize>
</triggeringPolicy>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="file"/>
<appender-ref ref="error"/>
</root>
</configuration>
2. 使用教程(包教包会)
为了文章简洁分成两篇了,点击链接直达->Springboot3的easycode模板 保姆级使用教程