Parcourir la source

mybatisplus代码生成器+模板

luojun il y a 2 ans
Parent
commit
f5d64365a2

+ 2 - 0
pom.xml

@@ -37,6 +37,8 @@
         <commons.lang3.version>3.12.0</commons.lang3.version>
         <okhttp.version>3.10.0</okhttp.version>
         <lombok.version>1.18.10</lombok.version>
+        <generator.version>3.2.0</generator.version>
+        <freemarker.version>2.7.2</freemarker.version>
     </properties>
     <dependencyManagement>
         <dependencies>

+ 26 - 0
soc-modules/soc-modules-system/pom.xml

@@ -78,6 +78,32 @@
             <version>${soc.version}</version>
         </dependency>
 
+        <!-- freemarker -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-freemarker</artifactId>
+            <version>${freemarker.version}</version>
+        </dependency>
+
+        <!--代码生成器包-->
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-generator</artifactId>
+            <version>${generator.version}</version>
+            <exclusions>
+                <exclusion>
+                    <artifactId>mybatis-plus-extension</artifactId>
+                    <groupId>com.baomidou</groupId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <!--lombok-->
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+
     </dependencies>
 
 </project>

+ 99 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/controller/SysJobController.java

@@ -0,0 +1,99 @@
+package com.xunmei.system.controller;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import org.springframework.web.bind.annotation.*;
+import com.xunmei.system.service.ISysJobService;
+import com.xunmei.system.domain.SysJob;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static com.xunmei.common.core.web.domain.AjaxResult.success;
+import static com.xunmei.common.core.web.domain.AjaxResult.error;
+import javax.annotation.Resource;
+import com.xunmei.common.security.annotation.RequiresPermissions;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ * SysJobController 前端控制器
+ * </p>
+ *
+ * @author luojun
+ * @since 2023-08-04
+ */
+@Api(tags = {"SysJobController"})
+@RestController
+@RequestMapping("/sysJob")
+public class SysJobController {
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+    @Resource
+    private ISysJobService sysJobService;
+
+
+    @ApiOperation(value = "新增定时任务调度表")
+    @RequiresPermissions("system:sysJob:add")
+    @PostMapping("/add")
+    public AjaxResult add(@RequestBody SysJob sysJob){
+        try {
+            return sysJobService.add(sysJob);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "删除定时任务调度表")
+    @RequiresPermissions("system:sysJob:delete")
+    @DeleteMapping("/{id}")
+    public AjaxResult delete(@PathVariable("id") Long id){
+        try {
+            return sysJobService.delete(id);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "更新定时任务调度表")
+    @RequiresPermissions("system:sysJob:update")
+    @PutMapping("/update")
+    public AjaxResult update(@RequestBody SysJob sysJob){
+        try {
+            return sysJobService.updateData(sysJob);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "查询定时任务调度表分页数据")
+    @RequiresPermissions("system:sysJob:findByPage")
+    @GetMapping("/findByPage")
+    public AjaxResult findListByPage(Page<SysJob> page,SysJob sysJob){
+        try {
+            return sysJobService.findListByPage(page, sysJob);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "id查询定时任务调度表")
+    @RequiresPermissions("system:sysJob:findById")
+    @GetMapping("/{id}")
+    public AjaxResult findById(@PathVariable Long id){
+        try {
+            return sysJobService.findById(id);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+}

+ 70 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/domain/SysJob.java

@@ -0,0 +1,70 @@
+package com.xunmei.system.domain;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 定时任务调度表
+ * </p>
+ *
+ * @author luojun
+ * @since 2023-08-04
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="SysJob对象", description="定时任务调度表")
+public class SysJob implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "任务ID")
+    @TableId(value = "job_id", type = IdType.AUTO)
+    private Long jobId;
+
+    @ApiModelProperty(value = "任务名称")
+    private String jobName;
+
+    @ApiModelProperty(value = "任务组名")
+    private String jobGroup;
+
+    @ApiModelProperty(value = "调用目标字符串")
+    private String invokeTarget;
+
+    @ApiModelProperty(value = "cron执行表达式")
+    private String cronExpression;
+
+    @ApiModelProperty(value = "计划执行错误策略(1立即执行 2执行一次 3放弃执行)")
+    private String misfirePolicy;
+
+    @ApiModelProperty(value = "是否并发执行(0允许 1禁止)")
+    private String concurrent;
+
+    @ApiModelProperty(value = "状态(0正常 1暂停)")
+    private String status;
+
+    @ApiModelProperty(value = "创建者")
+    private String createBy;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty(value = "更新者")
+    private String updateBy;
+
+    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+
+    @ApiModelProperty(value = "备注信息")
+    private String remark;
+
+
+}

+ 16 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/mapper/SysJobMapper.java

@@ -0,0 +1,16 @@
+package com.xunmei.system.mapper;
+
+import com.xunmei.system.domain.SysJob;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ * 定时任务调度表 Mapper 接口
+ * </p>
+ *
+ * @author luojun
+ * @since 2023-08-04
+ */
+public interface SysJobMapper extends BaseMapper<SysJob> {
+
+}

+ 58 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/ISysJobService.java

@@ -0,0 +1,58 @@
+package com.xunmei.system.service;
+
+import com.xunmei.system.domain.SysJob;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+
+/**
+ * <p>
+ * 定时任务调度表 服务类
+ * </p>
+ *
+ * @author luojun
+ * @since 2023-08-04
+ */
+public interface ISysJobService extends IService<SysJob> {
+
+    /**
+     * 查询定时任务调度表分页数据
+     *
+     * @param page      页码
+     * @param sysJob 每页条数
+     * @return AjaxResult
+     */
+    AjaxResult findListByPage(Page<SysJob> page,SysJob sysJob);
+
+    /**
+     * 添加定时任务调度表
+     *
+     * @param sysJob 定时任务调度表
+     * @return JsonBean
+     */
+    AjaxResult add(SysJob sysJob);
+
+    /**
+     * 删除定时任务调度表
+     *
+     * @param id 主键
+     * @return AjaxResult
+     */
+    AjaxResult delete(Long id);
+
+    /**
+     * 修改定时任务调度表
+     *
+     * @param sysJob 定时任务调度表
+     * @return AjaxResult
+     */
+    AjaxResult updateData(SysJob sysJob);
+
+    /**
+     * id查询数据
+     *
+     * @param id id
+     * @return AjaxResult
+     */
+    AjaxResult findById(Long id);
+}

+ 49 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/service/impl/SysJobServiceImpl.java

@@ -0,0 +1,49 @@
+package com.xunmei.system.service.impl;
+
+import com.xunmei.system.domain.SysJob;
+import com.xunmei.system.mapper.SysJobMapper;
+import com.xunmei.system.service.ISysJobService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import static com.xunmei.common.core.web.domain.AjaxResult.success;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+
+/**
+ * <p>
+ * 定时任务调度表 服务实现类
+ * </p>
+ *
+ * @author luojun
+ * @since 2023-08-04
+ */
+@Service
+public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements ISysJobService {
+
+    @Override
+    public AjaxResult findListByPage(Page<SysJob> page,SysJob sysJob){
+    QueryWrapper<SysJob> where = new QueryWrapper<>(sysJob);
+        return success(baseMapper.selectPage(page,where));
+    }
+
+    @Override
+    public AjaxResult add(SysJob sysJob){
+        return success(baseMapper.insert(sysJob));
+    }
+
+    @Override
+    public AjaxResult delete(Long id){
+        return success(baseMapper.deleteById(id));
+    }
+
+    @Override
+    public AjaxResult updateData(SysJob sysJob){
+        return success(baseMapper.updateById(sysJob));
+    }
+
+    @Override
+    public AjaxResult findById(Long id){
+        return success(baseMapper.selectById(id));
+    }
+}

+ 147 - 0
soc-modules/soc-modules-system/src/main/java/com/xunmei/system/util/Generator.java

@@ -0,0 +1,147 @@
+package com.xunmei.system.util;
+
+import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
+import com.baomidou.mybatisplus.core.toolkit.StringPool;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.generator.AutoGenerator;
+import com.baomidou.mybatisplus.generator.InjectionConfig;
+import com.baomidou.mybatisplus.generator.config.*;
+import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
+import com.baomidou.mybatisplus.generator.config.po.TableInfo;
+import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.IColumnType;
+import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
+import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+/**
+ * @author luojun
+ * @date 2022/8/11 16:41
+ */
+public class Generator {
+    /**
+     * <p>
+     * 读取控制台内容
+     * </p>
+     */
+    public static String scanner(String tip) {
+        Scanner scanner = new Scanner(System.in);
+        StringBuilder help = new StringBuilder();
+        help.append("请输入" + tip + ":");
+        System.out.println(help.toString());
+        if (scanner.hasNext()) {
+            String ipt = scanner.next();
+            if (StringUtils.isNotEmpty(ipt)) {
+                return ipt;
+            }
+        }
+        throw new MybatisPlusException("请输入正确的" + tip + "!");
+    }
+
+    public static void main(String[] args) {
+        // 代码生成器
+        AutoGenerator mpg = new AutoGenerator();
+
+        // 全局配置
+        GlobalConfig gc = new GlobalConfig();
+        String projectPath = System.getProperty("user.dir")+"\\soc-modules\\soc-modules-system" ;
+        gc.setOutputDir(projectPath + "/src/main/java");
+        gc.setAuthor("luojun");
+        gc.setOpen(false);
+        //是否覆盖文件
+        gc.setFileOverride(true);
+        // xml resultmap
+        gc.setBaseResultMap(true);
+        // xml columlist
+        gc.setBaseColumnList(true);
+        //实体属性 Swagger2 注解
+        gc.setSwagger2(true);
+        mpg.setGlobalConfig(gc);
+
+        // 数据源配置
+        DataSourceConfig dsc = new DataSourceConfig();
+//        dsc.setUrl("jdbc:mysql://10.87.10.227:3306/soc");
+//        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
+//        dsc.setUsername("root");
+//        dsc.setPassword("XM_zm2019");
+        dsc.setUrl("jdbc:mysql://10.87.11.94:3306/soc");
+        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
+        dsc.setUsername("root");
+        dsc.setPassword("XM_zm2019");
+        dsc.setTypeConvert(new MySqlTypeConvert(){
+            // 自定义数据库表字段类型转换【可选】
+            @Override
+            public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
+                if ( fieldType.toLowerCase().contains( "datetime" ) ) {
+                    return DbColumnType.DATE;
+                }
+                return super.processTypeConvert(globalConfig, fieldType);
+            }
+
+        });
+        mpg.setDataSource(dsc);
+
+        // 包配置
+        PackageConfig pc = new PackageConfig();
+//        String packgeName = scanner("包名");
+//        String packgeName = "";
+        pc.setParent("com.xunmei.system");
+        pc.setController("controller");
+        pc.setEntity("domain" );
+        pc.setService("service" );
+        pc.setServiceImpl("service.impl");
+        pc.setMapper("mapper");
+        pc.setXml("mapper.xml");
+        mpg.setPackageInfo(pc);
+
+        // 自定义配置
+        InjectionConfig cfg = new InjectionConfig() {
+            @Override
+            public void initMap() {
+                // to do nothing
+            }
+        };
+
+        // 如果模板引擎是 freemarker
+        String templatePath = "/templates/mapper.xml.ftl";
+
+        // 自定义输出配置
+        List<FileOutConfig> focList = new ArrayList<>();
+        // 自定义配置会被优先输出
+        focList.add(new FileOutConfig(templatePath) {
+            @Override
+            public String outputFile(TableInfo tableInfo) {
+                // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
+                return projectPath + "/src/main/resources/mapper/system/"
+                        + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
+            }
+        });
+
+        cfg.setFileOutConfigList(focList);
+        mpg.setCfg(cfg);
+
+        // 配置模板
+        TemplateConfig templateConfig = new TemplateConfig();
+        templateConfig.setXml(null);
+        mpg.setTemplate(templateConfig);
+
+        // 策略配置
+        StrategyConfig strategy = new StrategyConfig();
+        strategy.setNaming(NamingStrategy.underline_to_camel);
+        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
+        strategy.setEntityLombokModel(true);
+        strategy.setRestControllerStyle(true);
+
+        // 公共父类
+        // 写于父类中的公共字段
+        strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
+        strategy.setControllerMappingHyphenStyle(true);
+        strategy.setTablePrefix("t_");
+        mpg.setStrategy(strategy);
+        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
+        mpg.execute();
+    }
+}

+ 27 - 0
soc-modules/soc-modules-system/src/main/resources/mapper/system/SysJobMapper.xml

@@ -0,0 +1,27 @@
+<?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="com.xunmei.system.mapper.SysJobMapper">
+
+        <!-- 通用查询映射结果 -->
+        <resultMap id="BaseResultMap" type="com.xunmei.system.domain.SysJob">
+                    <id column="job_id" property="jobId"/>
+                    <result column="job_name" property="jobName"/>
+                    <result column="job_group" property="jobGroup"/>
+                    <result column="invoke_target" property="invokeTarget"/>
+                    <result column="cron_expression" property="cronExpression"/>
+                    <result column="misfire_policy" property="misfirePolicy"/>
+                    <result column="concurrent" property="concurrent"/>
+                    <result column="status" property="status"/>
+                    <result column="create_by" property="createBy"/>
+                    <result column="create_time" property="createTime"/>
+                    <result column="update_by" property="updateBy"/>
+                    <result column="update_time" property="updateTime"/>
+                    <result column="remark" property="remark"/>
+        </resultMap>
+
+        <!-- 通用查询结果列 -->
+        <sql id="Base_Column_List">
+            job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, update_by, update_time, remark
+        </sql>
+
+</mapper>

+ 110 - 0
soc-modules/soc-modules-system/src/main/resources/templates/controller.java.ftl

@@ -0,0 +1,110 @@
+package ${package.Controller};
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import org.springframework.web.bind.annotation.*;
+import ${package.Service}.${table.serviceName};
+import ${package.Entity}.${entity};
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import static com.xunmei.common.core.web.domain.AjaxResult.success;
+import static com.xunmei.common.core.web.domain.AjaxResult.error;
+import javax.annotation.Resource;
+import com.xunmei.common.security.annotation.RequiresPermissions;
+
+<#if restControllerStyle>
+import org.springframework.web.bind.annotation.RestController;
+<#else>
+import org.springframework.stereotype.Controller;
+</#if>
+<#if superControllerClassPackage??>
+import ${superControllerClassPackage};
+</#if>
+
+/**
+ * <p>
+ * ${table.controllerName!} 前端控制器
+ * </p>
+ *
+ * @author ${author}
+ * @since ${date}
+ */
+<#if restControllerStyle>
+@Api(tags = {"${table.controllerName!}"})
+@RestController
+<#else>
+@Controller
+</#if>@RequestMapping("/${entity?uncap_first}")
+<#if kotlin>class ${table.controllerName}<#if superControllerClass??>:${superControllerClass}()</#if><#else><#if superControllerClass??>public class ${table.controllerName} extends ${superControllerClass}{<#else>public class ${table.controllerName} {</#if>
+
+    private Logger log = LoggerFactory.getLogger(getClass());
+    @Resource
+    private ${table.serviceName} ${(table.serviceName?substring(1))?uncap_first};
+
+
+    @ApiOperation(value = "新增${table.comment!}")
+    @RequiresPermissions("${package.Controller?split('.')[2]}:${entity?uncap_first}:add")
+    @PostMapping("/add")
+    public AjaxResult add(@RequestBody ${entity} ${entity?uncap_first}){
+        try {
+            return ${(table.serviceName?substring(1))?uncap_first}.add(${entity?uncap_first});
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "删除${table.comment!}")
+    @RequiresPermissions("${package.Controller?split('.')[2]}:${entity?uncap_first}:delete")
+    @DeleteMapping("/{id}")
+    public AjaxResult delete(@PathVariable("id") Long id){
+        try {
+            return ${(table.serviceName?substring(1))?uncap_first}.delete(id);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "更新${table.comment!}")
+    @RequiresPermissions("${package.Controller?split('.')[2]}:${entity?uncap_first}:update")
+    @PutMapping("/update")
+    public AjaxResult update(@RequestBody ${entity} ${entity?uncap_first}){
+        try {
+            return ${(table.serviceName?substring(1))?uncap_first}.updateData(${entity?uncap_first});
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "查询${table.comment!}分页数据")
+    @RequiresPermissions("${package.Controller?split('.')[2]}:${entity?uncap_first}:findByPage")
+    @GetMapping("/findByPage")
+    public AjaxResult findListByPage(Page<${entity}> page,${entity} ${entity?uncap_first}){
+        try {
+            return ${(table.serviceName?substring(1))?uncap_first}.findListByPage(page, ${entity?uncap_first});
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+    @ApiOperation(value = "id查询${table.comment!}")
+    @RequiresPermissions("${package.Controller?split('.')[2]}:${entity?uncap_first}:findById")
+    @GetMapping("/{id}")
+    public AjaxResult findById(@PathVariable Long id){
+        try {
+            return ${(table.serviceName?substring(1))?uncap_first}.findById(id);
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            return error();
+        }
+    }
+
+}
+</#if>

+ 152 - 0
soc-modules/soc-modules-system/src/main/resources/templates/entity.java.ftl

@@ -0,0 +1,152 @@
+package ${package.Entity};
+
+<#list table.importPackages as pkg>
+import ${pkg};
+</#list>
+<#if swagger2>
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+</#if>
+<#if entityLombokModel>
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+</#if>
+
+/**
+ * <p>
+ * ${table.comment!}
+ * </p>
+ *
+ * @author ${author}
+ * @since ${date}
+ */
+<#if entityLombokModel>
+@Data
+    <#if superEntityClass??>
+@EqualsAndHashCode(callSuper = true)
+    <#else>
+@EqualsAndHashCode(callSuper = false)
+    </#if>
+@Accessors(chain = true)
+</#if>
+<#if table.convert>
+@TableName("${table.name}")
+</#if>
+<#if swagger2>
+@ApiModel(value="${entity}对象", description="${table.comment!}")
+</#if>
+<#if superEntityClass??>
+public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> {
+<#elseif activeRecord>
+public class ${entity} extends Model<${entity}> {
+<#else>
+public class ${entity} implements Serializable {
+</#if>
+
+<#if entitySerialVersionUID>
+    private static final long serialVersionUID = 1L;
+</#if>
+<#-- ----------  BEGIN 字段循环遍历  ---------->
+<#list table.fields as field>
+    <#if field.keyFlag>
+        <#assign keyPropertyName="${field.propertyName}"/>
+    </#if>
+
+    <#if field.comment!?length gt 0>
+        <#if swagger2>
+    @ApiModelProperty(value = "${field.comment}")
+        <#else>
+    /**
+     * ${field.comment}
+     */
+        </#if>
+    </#if>
+    <#if field.keyFlag>
+        <#-- 主键 -->
+        <#if field.keyIdentityFlag>
+    @TableId(value = "${field.name}", type = IdType.AUTO)
+        <#elseif idType??>
+    @TableId(value = "${field.name}", type = IdType.${idType})
+        <#elseif field.convert>
+    @TableId("${field.name}")
+        </#if>
+        <#-- 普通字段 -->
+    <#elseif field.fill??>
+    <#-- -----   存在字段填充设置   ----->
+        <#if field.convert>
+    @TableField(value = "${field.name}", fill = FieldFill.${field.fill})
+        <#else>
+    @TableField(fill = FieldFill.${field.fill})
+        </#if>
+    <#elseif field.convert>
+    @TableField("${field.name}")
+    </#if>
+    <#-- 乐观锁注解 -->
+    <#if (versionFieldName!"") == field.name>
+    @Version
+    </#if>
+    <#-- 逻辑删除注解 -->
+    <#if (logicDeleteFieldName!"") == field.name>
+    @TableLogic
+    </#if>
+    private ${field.propertyType} ${field.propertyName};
+</#list>
+<#------------  END 字段循环遍历  ---------->
+
+<#if !entityLombokModel>
+    <#list table.fields as field>
+        <#if field.propertyType == "boolean">
+            <#assign getprefix="is"/>
+        <#else>
+            <#assign getprefix="get"/>
+        </#if>
+    public ${field.propertyType} ${getprefix}${field.capitalName}() {
+        return ${field.propertyName};
+    }
+
+    <#if entityBuilderModel>
+    public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
+    <#else>
+    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
+    </#if>
+        this.${field.propertyName} = ${field.propertyName};
+        <#if entityBuilderModel>
+        return this;
+        </#if>
+    }
+    </#list>
+</#if>
+
+<#if entityColumnConstant>
+    <#list table.fields as field>
+    public static final String ${field.name?upper_case} = "${field.name}";
+
+    </#list>
+</#if>
+<#if activeRecord>
+    @Override
+    protected Serializable pkVal() {
+    <#if keyPropertyName??>
+        return this.${keyPropertyName};
+    <#else>
+        return null;
+    </#if>
+    }
+
+</#if>
+<#if !entityLombokModel>
+    @Override
+    public String toString() {
+        return "${entity}{" +
+    <#list table.fields as field>
+        <#if field_index==0>
+            "${field.propertyName}=" + ${field.propertyName} +
+        <#else>
+            ", ${field.propertyName}=" + ${field.propertyName} +
+        </#if>
+    </#list>
+        "}";
+    }
+</#if>
+}

+ 39 - 0
soc-modules/soc-modules-system/src/main/resources/templates/mapper.xml.ftl

@@ -0,0 +1,39 @@
+<?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="${package.Mapper}.${table.mapperName}">
+
+    <#if enableCache>
+        <!-- 开启二级缓存 -->
+        <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
+
+    </#if>
+    <#if baseResultMap>
+        <!-- 通用查询映射结果 -->
+        <resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
+            <#list table.fields as field>
+                <#if field.keyFlag><#--生成主键排在第一位-->
+                    <id column="${field.name}" property="${field.propertyName}"/>
+                </#if>
+            </#list>
+            <#list table.commonFields as field><#--生成公共字段 -->
+                <result column="${field.name}" property="${field.propertyName}"/>
+            </#list>
+            <#list table.fields as field>
+                <#if !field.keyFlag><#--生成普通字段 -->
+                    <result column="${field.name}" property="${field.propertyName}"/>
+                </#if>
+            </#list>
+        </resultMap>
+
+    </#if>
+    <#if baseColumnList>
+        <!-- 通用查询结果列 -->
+        <sql id="Base_Column_List">
+            <#list table.commonFields as field>
+                ${field.name},
+            </#list>
+            ${table.fieldNames}
+        </sql>
+
+    </#if>
+</mapper>

+ 62 - 0
soc-modules/soc-modules-system/src/main/resources/templates/service.java.ftl

@@ -0,0 +1,62 @@
+package ${package.Service};
+
+import ${package.Entity}.${entity};
+import ${superServiceClassPackage};
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.web.domain.AjaxResult;
+
+/**
+ * <p>
+ * ${table.comment!} 服务类
+ * </p>
+ *
+ * @author ${author}
+ * @since ${date}
+ */
+<#if kotlin>
+interface ${table.serviceName} : ${superServiceClass}<${entity}>
+<#else>
+public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
+
+    /**
+     * 查询${table.comment!}分页数据
+     *
+     * @param page      页码
+     * @param ${entity?uncap_first} 每页条数
+     * @return AjaxResult
+     */
+    AjaxResult findListByPage(Page<${entity}> page,${entity} ${entity?uncap_first});
+
+    /**
+     * 添加${table.comment!}
+     *
+     * @param ${entity?uncap_first} ${table.comment!}
+     * @return JsonBean
+     */
+    AjaxResult add(${entity} ${entity?uncap_first});
+
+    /**
+     * 删除${table.comment!}
+     *
+     * @param id 主键
+     * @return AjaxResult
+     */
+    AjaxResult delete(Long id);
+
+    /**
+     * 修改${table.comment!}
+     *
+     * @param ${entity?uncap_first} ${table.comment!}
+     * @return AjaxResult
+     */
+    AjaxResult updateData(${entity} ${entity?uncap_first});
+
+    /**
+     * id查询数据
+     *
+     * @param id id
+     * @return AjaxResult
+     */
+    AjaxResult findById(Long id);
+}
+</#if>

+ 55 - 0
soc-modules/soc-modules-system/src/main/resources/templates/serviceImpl.java.ftl

@@ -0,0 +1,55 @@
+package ${package.ServiceImpl};
+
+import ${package.Entity}.${entity};
+import ${package.Mapper}.${table.mapperName};
+import ${package.Service}.${table.serviceName};
+import ${superServiceImplClassPackage};
+import org.springframework.stereotype.Service;
+import com.xunmei.common.core.web.domain.AjaxResult;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import static com.xunmei.common.core.web.domain.AjaxResult.success;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+
+/**
+ * <p>
+ * ${table.comment!} 服务实现类
+ * </p>
+ *
+ * @author ${author}
+ * @since ${date}
+ */
+@Service
+<#if kotlin>
+open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
+
+}
+<#else>
+public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
+
+    @Override
+    public AjaxResult findListByPage(Page<${entity}> page,${entity} ${entity?uncap_first}){
+    QueryWrapper<${entity}> where = new QueryWrapper<>(${entity?uncap_first});
+        return success(baseMapper.selectPage(page,where));
+    }
+
+    @Override
+    public AjaxResult add(${entity} ${entity?uncap_first}){
+        return success(baseMapper.insert(${entity?uncap_first}));
+    }
+
+    @Override
+    public AjaxResult delete(Long id){
+        return success(baseMapper.deleteById(id));
+    }
+
+    @Override
+    public AjaxResult updateData(${entity} ${entity?uncap_first}){
+        return success(baseMapper.updateById(${entity?uncap_first}));
+    }
+
+    @Override
+    public AjaxResult findById(Long id){
+        return success(baseMapper.selectById(id));
+    }
+}
+</#if>