lichen 2 ay önce
ebeveyn
işleme
bf5ab0efb8

+ 94 - 0
pom.xml

@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.mcoding</groupId>
+    <artifactId>generator</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <java.version>1.8</java.version>
+        <mybatis-plus.version>3.0.6</mybatis-plus.version>
+        <freemarker.version>2.3.9</freemarker.version>
+        <mysql.version>8.0.16</mysql.version>
+        <logback.version>1.2.3</logback.version>
+        <spring.version>5.0.10.RELEASE</spring.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>2.2.1.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+            <version>2.9.2</version>
+        </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus</artifactId>
+            <version>${mybatis-plus.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.freemarker</groupId>
+            <artifactId>freemarker</artifactId>
+            <version>${freemarker.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>${mysql.version}</version>
+        </dependency>
+
+        <!-- logback -->
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-access</artifactId>
+            <version>${logback.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>${logback.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-core</artifactId>
+            <version>${logback.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.47</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-deploy-plugin</artifactId>
+                <version>2.7</version>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 139 - 0
src/main/java/com/mcoding/generator/CodeGenerator.java

@@ -0,0 +1,139 @@
+package com.mcoding.generator;
+
+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 wzt
+ */
+public class CodeGenerator {
+
+    static String URL = "jdbc:mysql://47.113.125.203:3306/music?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";
+    static String DRIVER = "com.mysql.cj.jdbc.Driver";
+    static String USERNAME = "music";
+    static String PASSWORD = "music_1234";
+
+    /**
+     * <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) {
+
+        // 全局配置
+        GlobalConfig globalConfig = new GlobalConfig();
+        String projectPath = System.getProperty("user.dir");
+        globalConfig.setOutputDir(projectPath + "/src/main/java");
+        globalConfig.setAuthor(scanner("作者"));
+        globalConfig.setOpen(false);
+        globalConfig.setActiveRecord(false);
+        globalConfig.setBaseColumnList(true);
+        globalConfig.setSwagger2(true);
+        globalConfig.setFileOverride(true);
+        globalConfig.setServiceName("%sService");
+
+        // 数据源配置
+        DataSourceConfig dataSourceConfig = new DataSourceConfig();
+        dataSourceConfig.setUrl(URL);
+        dataSourceConfig.setDriverName(DRIVER);
+        dataSourceConfig.setUsername(USERNAME);
+        dataSourceConfig.setPassword(PASSWORD);
+        dataSourceConfig.setTypeConvert(new MySqlTypeConvert() {
+            @Override
+            public IColumnType processTypeConvert(GlobalConfig globalConfig, String s) {
+                if ("datetime".equalsIgnoreCase(s) || "timestamp".equals(s)) {
+                    return DbColumnType.DATE;
+                }
+                return super.processTypeConvert(globalConfig, s);
+            }
+        });
+
+        // 包配置
+        PackageConfig packageConfig = new PackageConfig();
+        packageConfig.setModuleName(scanner("模块名"));
+        packageConfig.setParent("com.mcoding");
+
+        // 自定义配置
+        InjectionConfig injectionConfig = 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/" + packageConfig.getModuleName()
+                        + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
+            }
+        });
+
+        injectionConfig.setFileOutConfigList(focList);
+
+        // 配置模板
+        TemplateConfig templateConfig = new TemplateConfig();
+        templateConfig.setController("/templates/mybatis-plus/controller.java");
+        templateConfig.setEntity("/templates/mybatis-plus/entity.java");
+        templateConfig.setXml(null);
+
+        // 策略配置
+        StrategyConfig strategyConfig = new StrategyConfig();
+        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
+        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
+        strategyConfig.setEntityLombokModel(true);
+        strategyConfig.setRestControllerStyle(true);
+        strategyConfig.setTablePrefix("");
+        strategyConfig.setInclude(scanner("表名,多个英文逗号分割").split(","));
+        strategyConfig.setControllerMappingHyphenStyle(true);
+        strategyConfig.setTablePrefix(packageConfig.getModuleName() + "_");
+        strategyConfig.entityTableFieldAnnotationEnable(true);
+
+
+        new AutoGenerator()
+                .setGlobalConfig(globalConfig)
+                .setDataSource(dataSourceConfig)
+                .setPackageInfo(packageConfig)
+                .setCfg(injectionConfig)
+                .setTemplate(templateConfig)
+                .setTemplateEngine(new FreemarkerTemplateEngine())
+                .setStrategy(strategyConfig)
+                .execute();
+
+    }
+
+}

+ 23 - 0
src/main/java/com/mcoding/util/BeanMapperUtils.java

@@ -0,0 +1,23 @@
+package com.mcoding.util;
+
+
+import java.util.List;
+
+public abstract class BeanMapperUtils {
+
+
+    public static <S, D> D map(S source, Class<D> clazz) {
+        if (source == null) {
+            return null;
+        }
+
+        return null;
+    }
+
+
+    public static <S, D> List<D> mapAsList(List<S> source, Class<D> clazz) {
+        return null;
+    }
+
+
+}

+ 12 - 0
src/main/java/com/mcoding/util/IdObject.java

@@ -0,0 +1,12 @@
+package com.mcoding.util;
+
+import lombok.Data;
+
+/**
+ * @author wzt on 2020/2/14.
+ * @version 1.0
+ */
+@Data
+public class IdObject {
+    Integer id;
+}

+ 40 - 0
src/main/java/com/mcoding/util/MapUtils.java

@@ -0,0 +1,40 @@
+package com.mcoding.util;
+
+import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * @author wzt on 2020/1/16.
+ * @version 1.0
+ */
+public class MapUtils {
+
+    /**
+     * 对每个分组求和
+     *
+     * @param sourceMap
+     * @param function
+     * @param <S>
+     * @param <R>
+     * @return
+     */
+    public static <S, R> Map<String, BigDecimal> sumEachGroupList(Map<String, List<S>> sourceMap, Function<S, R> function) {
+
+        Map<String, BigDecimal> resultMap = new HashMap<>(sourceMap.size());
+
+        sourceMap.forEach((key, list) -> {
+            BigDecimal sum = BigDecimal.ZERO;
+            for (S t : list) {
+                R result = function.apply(t);
+                sum = sum.add(new BigDecimal(result.toString()));
+            }
+            resultMap.put(key, sum);
+        });
+
+        return resultMap;
+    }
+
+}

+ 23 - 0
src/main/java/com/mcoding/util/ModelAttrUtils.java

@@ -0,0 +1,23 @@
+package com.mcoding.util;
+
+import java.util.Map;
+
+/**
+ * @author wzt on 2020/2/11.
+ * @version 1.0
+ */
+public class ModelAttrUtils {
+
+    /**
+     * 根据Class定义生成模型属性
+     *
+     * @param clazz
+     * @param <T>
+     * @return
+     */
+    public static <T> Map<String, ModelFieldAttr> generateModelAttr(Class<T> clazz) {
+
+        return null;
+    }
+
+}

+ 16 - 0
src/main/java/com/mcoding/util/ModelFieldAttr.java

@@ -0,0 +1,16 @@
+package com.mcoding.util;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+/**
+ * @author wzt on 2020/2/12.
+ * @version 1.0
+ */
+@Data
+@AllArgsConstructor
+public class ModelFieldAttr {
+
+    private String tableFieldName;
+    private String modelFieldType;
+}

+ 31 - 0
src/main/java/com/mcoding/util/PageView.java

@@ -0,0 +1,31 @@
+package com.mcoding.util;
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author wzt on 2019/11/22.
+ * @version 1.0
+ */
+@Data
+@Builder
+public class PageView<T> {
+
+    private int current;
+    private int size;
+    private long total;
+
+    private List<T> records;
+
+
+    public static <T>  PageView<T> newPageView() {
+        return PageView.<T>builder().build();
+    }
+
+    public static <T> PageView<T> newPageView(int current, int size, long total) {
+        return PageView.<T>builder().current(current).size(size).total(total).build();
+    }
+
+}

+ 80 - 0
src/main/java/com/mcoding/util/ResponseCode.java

@@ -0,0 +1,80 @@
+package com.mcoding.util;
+
+/**
+ * 响应码:0表示成功,其他表示错误或失败
+ *
+ */
+public enum ResponseCode {
+
+	Success("200", "base_success", "操作成功"), 
+	ERROR("500", "base_error", "系统内部异常"), 
+	Fail("400", "base_fail", "操作失败"), 
+	Param_Error("400", "base_param_error", "参数异常"), 
+	Format_Error("415","base_format_error", "格式错误"), 
+	METHOD_NO_SUPPORT("405","base_method_no_support", "不支持当前请求方法"), 
+	No_Exist("410", "base_record_no_exist", "记录不存在或已被删除"),
+	
+	Chinese_Cannot_Be_Null("403","chinese_cannot_be_null","中文不能为空"),
+	
+	Account_Permission_denied("403", "base_permission_denied", "没有操作权限"),
+	Account_No_Login("401", "base_account_no_login", "没有登录,或登录已过期"),
+	
+	DATABASE_LENGTH_ERROR("403","database_length_error","输入的参数长度超标"),
+	DATABASE_PARSE_ERROR("403","database_parse_error","输入的参数类型或格式有误"),
+	DATABASE_OPERATE_ERROR("403","database_operate_error","数据库操作异常"),
+	
+	
+	Account_Create_Fail("403","base_account_cre_fail","创建账号失败"),
+	Account_Expired("403", "base_account_expired", "帐号已过期"),
+	Account_Disabled("403", "base_account_disabled", "帐号已禁用"),
+	Account_Locked("403", "base_account_locked", "帐号已锁定"),
+	The_Same_Account("403","base_the_same_account","已经存在相同的登录账号"),
+	Accouont_Password_Expired("403", "base_password_expired", "密码过期"),
+	Account_Password_Worng("403", "base_account_password_worng", "用户名或密码错误"),
+	Account_Username_Not_Found("401", "base_account_username_not_found", "找不到该帐号"),
+	Account_Sessioin_Expired("403", "base_account_session_expired", "session会话异常"),
+	Account_Captcha_Not_Found("403","base_account_captcha_not_found","验证码异常"),
+	Account_Captcha_Worng("403","base_account_captcha_worng","验证码有误"),
+	User_Not_Found("403","user_not_found","找不到该用户,无法操作"),
+	Can_Not_Be_Null("403","base_canot_be_null","不能为空"),
+	Is_Exists("403","base_is_exists","已存在,不可重复"),
+	Admin_Not_Allow_Oper("403","admin_not_allow_oper","管理员,不允许操作"),
+	Id_Is_Blank("403","id_is_blank","id为空,操作失败"),
+	Unable_System("403","unable_system","无法匹配系统"),
+	Illegal_Opertion("400","base_illegal_opertion","不合法操作"),
+	Donot_Exists("403","do_not_exists","不存在,无法操作"),
+	Data_Error("403","base_data_error","数据异常"),
+	Unable_To_Parse("403","unable_to_parse","参数格式,无法解析"),
+	Query_Condition_Cannot_Be_Empty("403","query_condition_cannot_be_empty","查询条件不能为空"),
+	Parameter_Incomplete("403","parameter_incomplete","参数不完整"),
+	Must_Be_Unique("403","must_be_unique","必须唯一"),
+	Unrecognized("400","unrecognized","无法识别"),
+	IsNull("403","isNull","为空,无法操作"),
+	Has_Be_Confirm("403","has_be_confirm","已经确认,无法再修改"),
+	Already_In_Use("403","already_in_use","已被使用"),
+	Achieve_Fail("403","achieve_fail","获取失败");
+	
+	private String httpCode;
+	private String key;
+	private String msg;
+
+	private ResponseCode(String httpCode, String key, String msg) {
+		this.httpCode = httpCode;
+		this.key = key;
+		this.msg = msg;
+	}
+
+	
+	public String getCode() {
+		return httpCode;
+	}
+
+	public String getKey() {
+		return key;
+	}
+
+	public String getMsg() {
+		return msg;
+	}
+
+}

+ 47 - 0
src/main/java/com/mcoding/util/ResponseResult.java

@@ -0,0 +1,47 @@
+package com.mcoding.util;
+
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @author wzt
+ */
+@Builder
+@Data
+public class ResponseResult<T> implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String code;
+
+    private String msg;
+
+    private T data;
+
+    public static ResponseResult<String> success() {
+        return success(null);
+    }
+
+    public static <T> ResponseResult<T> success(T data) {
+        return ResponseResult.<T>builder()
+                .code(ResponseCode.Success.getCode())
+                .msg(ResponseCode.Success.getMsg())
+                .data(data)
+                .build();
+    }
+
+    public static ResponseResult<String> fail(String msg) {
+        return fail(ResponseCode.Fail, msg);
+    }
+
+    public static <T> ResponseResult<T> fail(ResponseCode responseCode, String msg) {
+        return ResponseResult.<T>builder()
+                .code(responseCode.getCode())
+                .msg(msg)
+                .build();
+    }
+
+}

+ 101 - 0
src/main/java/com/mcoding/util/SmartWrapper.java

@@ -0,0 +1,101 @@
+package com.mcoding.util;
+
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.Getter;
+
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * @author wzt on 2020/2/11.
+ * @version 1.0
+ */
+@Getter
+public class SmartWrapper<T> {
+
+    private boolean isContainOrderByCommand = false;
+
+    private int current = 1;
+
+    private int size = 10;
+
+    private QueryWrapper<T> queryWrapper = new QueryWrapper<>();
+
+    private Map<String, ModelFieldAttr> modelFieldToTableField = null;
+
+    public static <T> SmartWrapper<T> newWrapper() {
+        return new SmartWrapper<>();
+    }
+
+    public IPage<T> generatePage() {
+        return new Page<>(this.current, this.size);
+    }
+
+    /**
+     * 解析JSON查询字符串, 构建QueryWrapper对象
+     *
+     * @param queryObject
+     * @param clazz
+     * @return
+     */
+    public void parse(JSONObject queryObject, Class<T> clazz) {
+        if (Objects.isNull(queryObject)) {
+            return;
+        }
+
+        // 获取模型字段元信息
+        modelFieldToTableField = ModelAttrUtils.generateModelAttr(clazz);
+
+        // 解析查询条件
+        this.parseQueryCondition(queryObject, clazz);
+
+        // 解析排序条件
+        this.parseOrderByCondition(queryObject);
+
+        // 解析分页信息
+        this.parsePage(queryObject);
+    }
+
+
+    private void parsePage(JSONObject queryObject) {
+        if (Objects.isNull(queryObject)) {
+            return;
+        }
+
+        Object current = queryObject.get("current");
+        Object size = queryObject.get("size");
+        if (current == null || size == null) {
+            return;
+        }
+
+        this.current = (int) current;
+        this.size = (int) size;
+    }
+
+    /**
+     * 解析排序条件
+     *
+     * @param queryObject
+     * @return
+     */
+    private void parseOrderByCondition(JSONObject queryObject) {
+
+
+    }
+
+    /**
+     * 根据自定义语法解析查询条件
+     *
+     * @param queryObject
+     * @param clazz
+     * @return
+     */
+    private void parseQueryCondition(JSONObject queryObject, Class<T> clazz) {
+
+    }
+
+}

+ 79 - 0
src/main/resources/templates/mybatis-plus/controller.java.ftl

@@ -0,0 +1,79 @@
+package ${package.Controller};
+
+
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import javax.validation.Valid;
+
+import com.alibaba.fastjson.JSONObject;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+
+import com.mcoding.util.*;
+
+import ${package.Service}.${table.serviceName};
+import ${package.Entity}.${entity};
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+/**
+ * <p>
+ * ${table.comment!}
+ * </p>
+ *
+ * @author ${author}
+ * @since ${date}
+ */
+@Api(tags = "${table.comment!}服务")
+@RestController
+public class ${table.controllerName} {
+
+    @Resource
+    private ${table.serviceName} ${table.serviceName ? uncap_first};
+
+    @ApiOperation("创建")
+    @PostMapping("/service/${package.ModuleName}/create")
+    public ResponseResult<String> create(@Valid @RequestBody ${entity} ${entity ? uncap_first}) {
+        ${table.serviceName ? uncap_first}.save(${entity ? uncap_first});
+        return ResponseResult.success();
+    }
+
+    @ApiOperation(value = "删除")
+    @PostMapping("/service/${package.ModuleName}/delete")
+    public ResponseResult<String> delete(@RequestParam Integer id) {
+        ${table.serviceName ? uncap_first}.removeById(id);
+        return ResponseResult.success();
+    }
+
+    @ApiOperation(value = "修改")
+    @PostMapping("/service/${package.ModuleName}/modify")
+    public ResponseResult<String> modify(@Valid @RequestBody ${entity} ${entity ? uncap_first}) {
+        ${table.serviceName ? uncap_first}.updateById(${entity ? uncap_first});
+        return ResponseResult.success();
+    }
+
+    @ApiOperation(value = "查询活动详情")
+    @GetMapping("/service/${package.ModuleName}/detail")
+    public ResponseResult<${entity}> detail(@RequestParam Integer id) {
+        return ResponseResult.success(${table.serviceName ? uncap_first}.getById(id));
+    }
+
+    @ApiOperation(value = "分页查询")
+    @PostMapping("/service/${package.ModuleName}/queryByPage")
+    public ResponseResult<IPage<${entity}>> queryByPage(@RequestBody JSONObject queryObject) {
+
+         SmartWrapper<${entity}> smartWrapper = new SmartWrapper<>();
+         smartWrapper.parse(queryObject, ${entity}.class);
+
+         QueryWrapper<${entity}> queryWrapper = smartWrapper.getQueryWrapper();
+         IPage<${entity}> page = smartWrapper.generatePage();
+         ${table.serviceName ? uncap_first}.page(page, queryWrapper);
+         return ResponseResult.success(page);
+    }
+
+}

+ 150 - 0
src/main/resources/templates/mybatis-plus/entity.java.ftl

@@ -0,0 +1,150 @@
+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>
+
+import com.baomidou.mybatisplus.annotation.TableName;
+
+/**
+ * <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>
+@TableName("${table.name}")
+<#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>
+
+    private static final long serialVersionUID = 1L;
+<#-- ----------  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>
+}