初始化
This commit is contained in:
@ -0,0 +1,182 @@
|
||||
##导入宏定义
|
||||
$!{define.vm}
|
||||
$!{mybatisCodehelper.vm}
|
||||
|
||||
##设置表后缀(宏定义)
|
||||
#set($controllerName = $tool.append($tableInfo.name, "Controller"))
|
||||
##设置回调
|
||||
#set($controllerSavePath = $tool.append(${controllerSrcFolder},"/",${controllerPackageName.replace(".","/")}))
|
||||
|
||||
$!callback.setSavePath($controllerSavePath)
|
||||
$!callback.setFileName($tool.append($controllerName, ".java"))
|
||||
|
||||
##定义服务名
|
||||
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
|
||||
|
||||
##定义实体对象名
|
||||
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
|
||||
|
||||
package ${controllerPackageName};
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import {{ cookiecutter.__mvn_package }}.rest.api.ApiController;
|
||||
import {{ cookiecutter.__mvn_package }}.rest.api.R;
|
||||
import $!{modelPackageName}.$!{tableInfo.name};
|
||||
import ${servicePackageName}.$!{tableInfo.name}Service;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表控制层.")
|
||||
###if(${tableInfo.comment})
|
||||
##@Tag(name = "${tableInfo.comment}")
|
||||
###end
|
||||
@Tag(name = "标准接口", description = "由表结构自动生成")
|
||||
@RestController
|
||||
@RequestMapping("db/$!tool.firstLowerCase($!tableInfo.name)")
|
||||
public class $!{tableInfo.name}Controller extends ApiController {
|
||||
/** 服务对象. */
|
||||
private final $!{tableInfo.name}Service $!{serviceName};
|
||||
|
||||
public $!{tableInfo.name}Controller($!{tableInfo.name}Service $!{serviceName}) {
|
||||
this.$!{serviceName} = $!{serviceName};
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询所有数据.
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param $!entityName 查询实体
|
||||
* @return 分页数据
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 分页查询所有数据",
|
||||
parameters = {
|
||||
@Parameter(name = "page", description = "分页对象"),
|
||||
@Parameter(name = "$!entityName", description = "查询实体"),
|
||||
},
|
||||
responses = @ApiResponse(description = "分页数据"),
|
||||
description = "size=-1时查询所有数据,orders配合asc排序")
|
||||
@GetMapping
|
||||
@SaCheckPermission("db:rest:get")
|
||||
public R selectAll(@Nullable PageDTO<$!{tableInfo.name}> page, @Nullable $!{tableInfo.name} $!entityName) {
|
||||
return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键查询单条数据.
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 单条数据
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 通过主键查询单条数据",
|
||||
parameters = {
|
||||
@Parameter(name = "id", description = "主键", schema = @Schema(type = "string")),
|
||||
},
|
||||
responses = @ApiResponse(description = "单条数据"))
|
||||
@GetMapping("{id}")
|
||||
@SaCheckPermission("db:rest:get")
|
||||
public R selectOne(@PathVariable Serializable id) {
|
||||
return success(this.$!{serviceName}.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据.
|
||||
*
|
||||
* @param $!entityName 实体对象
|
||||
* @return 新增结果
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 新增数据",
|
||||
parameters = {
|
||||
@Parameter(name = "$!entityName", description = "实体对象"),
|
||||
},
|
||||
responses = @ApiResponse(description = "新增结果"))
|
||||
@PostMapping
|
||||
@SaCheckPermission("db:rest:post")
|
||||
public R insert(@RequestBody $!tableInfo.name $!entityName) {
|
||||
return success(this.$!{serviceName}.save($!entityName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量新增数据.
|
||||
*
|
||||
* @param $!{entityName}s 实体对象
|
||||
* @return 新增结果
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 批量新增数据",
|
||||
parameters = {
|
||||
@Parameter(name = "$!{entityName}s", description = "实体对象"),
|
||||
},
|
||||
responses = @ApiResponse(description = "新增结果"))
|
||||
@PostMapping("s")
|
||||
@SaCheckPermission("db:rest:post")
|
||||
public R inserts(@RequestBody List<$!tableInfo.name> $!{entityName}s) {
|
||||
return success(this.$!{serviceName}.saveBatch($!{entityName}s));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据.
|
||||
*
|
||||
* @param $!entityName 实体对象
|
||||
* @return 修改结果
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 修改数据",
|
||||
parameters = {@Parameter(name = "$!entityName", description = "实体对象")},
|
||||
responses = @ApiResponse(description = "修改结果"),
|
||||
description = "不存在的对象会新增")
|
||||
@PutMapping
|
||||
@SaCheckPermission("db:rest:put")
|
||||
public R update(@RequestBody $!tableInfo.name $!entityName) {
|
||||
return success(this.$!{serviceName}.saveOrUpdate($!entityName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改数据.
|
||||
*
|
||||
* @param $!{entityName}s 实体对象
|
||||
* @return 修改结果
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 批量修改数据",
|
||||
parameters = {@Parameter(name = "$!{entityName}s", description = "实体对象")},
|
||||
responses = @ApiResponse(description = "修改结果"),
|
||||
description = "不存在的对象会新增")
|
||||
@PutMapping("s")
|
||||
@SaCheckPermission("db:rest:put")
|
||||
public R updates(@RequestBody List<$!tableInfo.name> $!{entityName}s) {
|
||||
return success(this.$!{serviceName}.saveOrUpdateBatch($!{entityName}s));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据.
|
||||
*
|
||||
* @param idList 主键结合
|
||||
* @return 删除结果
|
||||
*/
|
||||
@Operation(
|
||||
summary = "${tableInfo.comment} - 删除数据",
|
||||
parameters = {
|
||||
@Parameter(name = "idList", description = "主键结合", schema = @Schema(type = "string"))
|
||||
},
|
||||
responses = @ApiResponse(description = "删除结果"),
|
||||
description = "主键用逗号拼接")
|
||||
@DeleteMapping
|
||||
@SaCheckPermission("db:rest:del")
|
||||
public R delete(@RequestParam("idList") List<Long> idList) {
|
||||
return success(this.$!{serviceName}.removeByIds(idList));
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
##导入宏定义
|
||||
$!{define.vm}
|
||||
$!{mybatisCodehelper.vm}
|
||||
|
||||
##设置表后缀(宏定义)
|
||||
#set($daoName = $tool.append($tableInfo.name, ${daoSuffix}))
|
||||
##设置回调
|
||||
#set($daoSavePath = $tool.append(${mapperSrcFolder},"/",${mapperPackageName.replace(".","/")}))
|
||||
|
||||
$!callback.setSavePath($daoSavePath)
|
||||
$!callback.setFileName($tool.append($daoName, ".java"))
|
||||
|
||||
package ${mapperPackageName};
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import $!{modelPackageName}.$!{tableInfo.name};
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表数据库访问层.")
|
||||
public interface $!{tableInfo.name}Dao extends BaseMapper<$!tableInfo.name> {
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
##导入宏定义
|
||||
$!{define.vm}
|
||||
$!{mybatisCodehelper.vm}
|
||||
|
||||
#set($entitySavePath = $tool.append(${javamodelSrcFolder},"/",${modelPackageName.replace(".","/")}))
|
||||
|
||||
$!callback.setSavePath($entitySavePath)
|
||||
$!callback.setFileName($tool.append($tableInfo.name, ".java"))
|
||||
|
||||
##自动导入包(全局变量)
|
||||
package ${modelPackageName};
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.Version;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import ltd.llvy.postgis.handler.GeometryDeserializer;
|
||||
import ltd.llvy.postgis.handler.GeometrySerializer;
|
||||
|
||||
import java.io.Serializable;
|
||||
$!autoImport
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表实体类.")
|
||||
#if(${tableInfo.comment})
|
||||
@Schema(description = "${tableInfo.comment}")
|
||||
#end
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class $!{tableInfo.name} extends Model<$!{tableInfo.name}> {
|
||||
#foreach($column in $tableInfo.fullColumn)
|
||||
#if(${column.comment})
|
||||
//${column.comment}
|
||||
#end
|
||||
#if($!{column.name} == "id" || $!{column.name.indexOf("Id")} != -1)
|
||||
@Schema(description = "${column.comment}", type = "string")
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
#else
|
||||
@Schema(description = "${column.comment}")
|
||||
#end
|
||||
#if("password" == $!{column.name})
|
||||
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||
#end
|
||||
#if("version" == $!{column.name})
|
||||
@Version
|
||||
#end
|
||||
#if("deleteTime" == $!{column.name})
|
||||
@TableLogic
|
||||
#end
|
||||
#if("createTime" == $!{column.name})
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
{% if cookiecutter.platform == "postgis" -%}
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.OTHER)
|
||||
{% else %}
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.DATETIMEOFFSET)
|
||||
{% endif %}
|
||||
#end
|
||||
#if("updateTime" == $!{column.name})
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
{% if cookiecutter.platform == "postgis" -%}
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.OTHER)
|
||||
{% else %}
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE, jdbcType = JdbcType.DATETIMEOFFSET)
|
||||
{% endif %}
|
||||
#end
|
||||
#if("createBy" == $!{column.name})
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
#end
|
||||
#if("updateBy" == $!{column.name})
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
#end
|
||||
#if("geom" == $!{column.name})
|
||||
@JsonSerialize(using = GeometrySerializer.class)
|
||||
@JsonDeserialize(using = GeometryDeserializer.class)
|
||||
#end
|
||||
private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
|
||||
#end
|
||||
#foreach($column in $tableInfo.pkColumn)
|
||||
/**
|
||||
* 获取主键值.
|
||||
*
|
||||
* @return 主键值
|
||||
*/
|
||||
@Override
|
||||
public Serializable pkVal () {
|
||||
return this.$!column.name;
|
||||
}
|
||||
#break
|
||||
#end
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
##引入mybatis支持
|
||||
$!{mybatisCodehelper.vm}
|
||||
$!{mybatisSupport.vm}
|
||||
##设置保存名称与保存位置
|
||||
#set($XmlSavePath = $tool.append(${mapperXmlFolder},"/",${mapperXmlPackage.replace(".","/")}))
|
||||
$!callback.setSavePath($XmlSavePath)
|
||||
$!callback.setFileName($tool.append($!{tableInfo.name}, $!{mapperSuffix},".xml"))
|
||||
#set($daoName = $tool.append($tableInfo.name, ${daoSuffix}))
|
||||
##拿到主键
|
||||
#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="{{ cookiecutter.__mvn_package }}.rest.dao.$!{tableInfo.name}Dao">
|
||||
<resultMap type="{{ cookiecutter.__mvn_package }}.rest.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>
|
||||
</mapper>
|
@ -0,0 +1,24 @@
|
||||
##导入宏定义
|
||||
$!{define.vm}
|
||||
|
||||
##定义初始变量
|
||||
$!{mybatisCodehelper.vm}
|
||||
#set($serviceName = $tool.append($tableInfo.name, "Service"))
|
||||
##设置回调
|
||||
#set($serviceSavePath = $tool.append(${serviceSrcFolder},"/",${servicePackageName.replace(".","/")}))
|
||||
|
||||
$!callback.setSavePath($serviceSavePath)
|
||||
$!callback.setFileName($tool.append($serviceName, ".java"))
|
||||
|
||||
|
||||
|
||||
package $!{servicePackageName};
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import $!{modelPackageName}.$!{tableInfo.name};
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表服务接口.")
|
||||
public interface $!{serviceName} extends IService
|
||||
|
||||
<$!tableInfo.name> {
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
##导入宏定义
|
||||
$!{define.vm}
|
||||
|
||||
$!{mybatisCodehelper.vm}
|
||||
#set($ServiceImplName = $tool.append($tableInfo.name, "ServiceImpl"))
|
||||
##设置回调
|
||||
##$!callback.setFileName($tool.append($ServiceImplName, ".java"))
|
||||
##$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
|
||||
#set($serviceImplSavePath = $tool.append(${serviceImplSrcFolder},"/",${serviceImplPackageName.replace(".","/")}))
|
||||
|
||||
$!callback.setSavePath($serviceImplSavePath)
|
||||
$!callback.setFileName($tool.append($ServiceImplName, ".java"))
|
||||
|
||||
#set($daoName = $tool.append($tableInfo.name, ${daoSuffix}))
|
||||
|
||||
package $!{serviceImplPackageName};
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import ${mapperPackageName}.${daoName};
|
||||
import $!{modelPackageName}.$!{tableInfo.name};
|
||||
import ${servicePackageName}.$!{tableInfo.name}Service;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
##表注释(宏定义)
|
||||
#tableComment("表服务实现类.")
|
||||
@Service("$!tool.firstLowerCase($tableInfo.name)Service")
|
||||
public class $!{ServiceImplName} extends ServiceImpl<$!{daoName}, $!{tableInfo.name}> implements
|
||||
|
||||
$!{tableInfo.name}Service {
|
||||
}
|
Reference in New Issue
Block a user