①:新建文件:EasyCodeConfig.json,然后将下面的代码复制到此文件中,最后通过导入文件的方式将模版导入进去
{
"author": "zhangsan",
"version": "1.2.4",
"userSecure": "",
"currTypeMapperGroupName": "Default",
"currTemplateGroupName": "zhangsan_MybatisPlus",
"currColumnConfigGroupName": "Default",
"currGlobalConfigGroupName": "Default",
"typeMapper": {},
"template": {
"zhangsan_MybatisPlus": {
"name": "zhangsan_MybatisPlus",
"elementList": [{
"name": "controller.java.vm",
"code": "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Controller\")\n\n##保存文件(宏定义)\n#save(\"/controller\", \"Controller.java\")\n##包路径(宏定义)\n#setPackageSuffix(\"controller\")\n##定义服务名\n#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), \"Service\"))\n##定义实体对象名\n#set($entityName = $!tool.firstLowerCase($!tableInfo.name))\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.web.bind.annotation.*;\nimport javax.annotation.Resource;\n\n##表注释(宏定义)\n#tableComment(\"表控制层\")\n@RestController\n@RequestMapping(\"$!tool.firstLowerCase($!tableInfo.name)\")\npublic class $!{tableName} {\n /**\n * 服务对象\n */\n @Resource\n private $!{tableInfo.name}Service $!{serviceName};\n\n \n \n}\n"
}, {
"name": "service.java.vm",
"code": "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Service\")\n\n##保存文件(宏定义)\n#save(\"/service\", \"Service.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"service\")\n\nimport com.baomidou.mybatisplus.extension.service.IService;\nimport $!{tableInfo.savePackageName}.model.entity.$!tableInfo.name;\n\n##表注释(宏定义)\n#tableComment(\"表服务接口\")\npublic interface $!{tableName} extends IService<$!tableInfo.name> {\n\n}\n"
}, {
"name": "serviceImpl.java.vm",
"code": "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"ServiceImpl\")\n\n##保存文件(宏定义)\n#save(\"/service/impl\", \"ServiceImpl.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"service.impl\")\n\nimport com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;\nimport $!{tableInfo.savePackageName}.mapper.$!{tableInfo.name}Mapper;\nimport $!{tableInfo.savePackageName}.model.entity.$!{tableInfo.name};\nimport $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;\nimport org.springframework.stereotype.Service;\n\n##表注释(宏定义)\n#tableComment(\"表服务实现类\")\n@Service(\"$!tool.firstLowerCase($tableInfo.name)Service\")\npublic class $!{tableName} extends ServiceImpl<$!{tableInfo.name}Mapper, $!{tableInfo.name}> implements $!{tableInfo.name}Service {\n\n}\n"
}, {
"name": "mapper.java.vm",
"code": "##导入宏定义\n$!{define.vm}\n\n##设置表后缀(宏定义)\n#setTableSuffix(\"Mapper\")\n\n##保存文件(宏定义)\n#save(\"/mapper\", \"Mapper.java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"mapper\")\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport $!{tableInfo.savePackageName}.model.entity.$!tableInfo.name;\nimport org.apache.ibatis.annotations.Mapper;\n\n##表注释(宏定义)\n#tableComment(\"表数据库访问层\")\n@Mapper\npublic interface $!{tableName} extends BaseMapper<$!tableInfo.name> {\n\n}\n"
}, {
"name": "entity.java.vm",
"code": "##引入宏定义\n$!{define.vm}\n \n##保存文件(宏定义)\n#save(\"/model/entity\", \".java\")\n\n##包路径(宏定义)\n#setPackageSuffix(\"model.entity\")\n \n##使用全局变量实现默认包导入\n$!{autoImport.vm}\nimport com.baomidou.mybatisplus.extension.activerecord.Model;\nimport com.baomidou.mybatisplus.annotation.*;\nimport lombok.AllArgsConstructor;\nimport lombok.Data;\nimport lombok.experimental.Accessors;\nimport lombok.EqualsAndHashCode;\n \n##使用宏定义实现类注释信息\n#tableComment(\"实体类\")\n@Data\n@Accessors(chain = true)\n@AllArgsConstructor\n@EqualsAndHashCode(callSuper = true)\n@TableName(value = \"$!{tableInfo.obj.name}\")\npublic class $!{tableInfo.name} extends Model<$!{tableInfo.name}> {\n private static final long serialVersionUID = $!tool.serial();\n \n## 主键列\n#foreach($column in $tableInfo.pkColumn)\n #if(${column.comment})/**\n * ${column.comment}\n */\n #end\n@TableId(value = \"$tool.hump2Underline($column.name)\",type=IdType.INPUT)\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n#end\n \n## 其他列\n#foreach($column in $tableInfo.otherColumn)\n #if(${column.comment})/**\n * ${column.comment}\n */\n #end\n@TableField(value = \"$tool.hump2Underline($column.name)\")\n private $!{tool.getClsNameByFullName($column.type)} $!{column.name};\n \n#end\n##foreach($column in $tableInfo.fullColumn)\n###使用宏定义实现get,set方法\n##getSetMethod($column)\n##end\n}"
}]
}
},
"columnConfig": {},
"globalConfig": {}
}
②:导入方式截图
package cn.nhdc.cloud.mudules.app.controller;
import cn.nhdc.cloud.mudules.app.service.ProjInfoService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* 测试项目(ProjInfo)表控制层
*
* @author zhangsan
* @since 2021-12-10 17:33:45
*/
@RestController
@RequestMapping("projInfo")
public class ProjInfoController {
/**
* 服务对象
*/
@Resource
private ProjInfoService projInfoService;
}
②:Service
package cn.nhdc.cloud.mudules.app.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.nhdc.cloud.mudules.app.model.entity.ProjInfo;
/**
* 测试项目(ProjInfo)表服务接口
*
* @author zhangsan
* @since 2021-12-13 13:48:10
*/
public interface ProjInfoService extends IService {
}
③:ServiceImpl
package cn.nhdc.cloud.mudules.app.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.nhdc.cloud.mudules.app.mapper.ProjInfoMapper;
import cn.nhdc.cloud.mudules.app.model.entity.ProjInfo;
import cn.nhdc.cloud.mudules.app.service.ProjInfoService;
import org.springframework.stereotype.Service;
/**
* 测试项目(ProjInfo)表服务实现类
*
* @author zhangsan
* @since 2021-12-13 13:48:10
*/
@Service("projInfoService")
public class ProjInfoServiceImpl extends ServiceImpl implements ProjInfoService {
}
④:Mapper
package cn.nhdc.cloud.mudules.app.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.nhdc.cloud.mudules.app.model.entity.ProjInfo;
import org.apache.ibatis.annotations.Mapper;
/**
* 测试项目(ProjInfo)表数据库访问层
*
* @author zhangsan
* @since 2021-12-13 13:48:10
*/
@Mapper
public interface ProjInfoMapper extends BaseMapper {
}
⑤:Model实体
package cn.nhdc.cloud.mudules.app.model.entity;
import java.util.Date;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.EqualsAndHashCode;
/**
* 测试项目(ProjInfo)实体类
*
* @author zhangsan
* @since 2021-12-13 13:48:10
*/
@Data
@Accessors(chain = true)
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(value = "app_proj_info")
public class ProjInfo extends Model {
private static final long serialVersionUID = -33145280060746223L;
/**
* 主键
*/
@TableId(value = "id",type=IdType.INPUT)
private Long id;
/**
* 名称
*/
@TableField(value = "name")
private String name;
/**
* 测试时间
*/
@TableField(value = "create_date")
private Date createDate;
}