SpringBoot JPA 代码自动生成 其三

之前说过怎么生成,可以参考这里可以一键生成entityservicerepository类了。

这个是对生成的内容进行扩展,在写一些基础、公共的组件时,不太希望使用lombok注解,反而需要最原始的getset方法,这个就是加上可以生成getset方法的配置。顺便加上了注释。

先看看新的实体类

  • 不使用lombok
package com.example.genpojodemo.entity;

import javax.persistence.*;

/**
 * 用户表
 */
@Entity
@Table(name = "user")
public class User {


    /**
     * id
     * default value: null
     */
    @Id
    @Column(name = "id", nullable = false, length = 20)
    private Long id;

    /**
     * 用户名
     * default value: 'a'
     */
    @Column(name = "username", nullable = true, length = 255)
    private String username;

    /**
     * 密码
     * default value: 'b'
     */
    @Column(name = "password", nullable = true, length = 255)
    private String password;

    /**
     * 盐
     * default value: 'b'
     */
    @Column(name = "salt", nullable = true, length = 255)
    private String salt;

    /**
     * 生成时间
     * default value: CURRENT_TIMESTAMP(6)
     */
    @Column(name = "create_time", nullable = true, length = 6)
    private java.util.Date createTime;

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return this.salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public java.util.Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(java.util.Date createTime) {
        this.createTime = createTime;
    }
}

  • 使用lombok
package com.example.genpojodemo.entity;

import lombok.Data;

import javax.persistence.*;

/**
 * 用户表
 */
@Data
@Entity
@Table(name = "user")
public class User {

    /**
     * id
     * default value: null
     */
    @Id
    @Column(name = "id", nullable = false, length = 20)
    private Long id;

    /**
     * 用户名
     * default value: 'a'
     */
    @Column(name = "username", nullable = true, length = 255)
    private String username;

    /**
     * 密码
     * default value: 'b'
     */
    @Column(name = "password", nullable = true, length = 255)
    private String password;

    /**
     * 盐
     * default value: 'b'
     */
    @Column(name = "salt", nullable = true, length = 255)
    private String salt;

    /**
     * 生成时间
     * default value: CURRENT_TIMESTAMP(6)
     */
    @Column(name = "create_time", nullable = true, length = 6)
    private java.util.Date createTime;
}

来看看Groovy内容

import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil

config = [
        impSerializable  : false,
        extendBaseEntity : false,
        extendBaseService: false,
        useLombok        : true, // 不使用会生成get、set方法

        // 不生成哪个就注释哪个
        generateItem     : [
                "Entity",
//                "Service",
//                "Repository",
//                "RepositoryCustom",
//                "RepositoryImpl",
        ]
]

baseEntityPackage = "com.yija.project.framework.base.BaseEntity"
baseServicePackage = "com.yija.project.framework.base.BaseService"
baseEntityProperties = ["id", "createDate", "lastModifiedDate", "version"]

typeMapping = [
        (~/(?i)bool|boolean|tinyint/)     : "Boolean",
        (~/(?i)bigint/)                   : "Long",
        (~/int/)                          : "Integer",
        (~/(?i)float|double|decimal|real/): "Double",
        (~/(?i)datetime|timestamp/)       : "java.util.Date",
        (~/(?i)date/)                     : "java.sql.Date",
        (~/(?i)time/)                     : "java.sql.Time",
        (~/(?i)/)                         : "String"
]

FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
    SELECTION.filter {
        it instanceof DasTable && it.getKind() == ObjectKind.TABLE
    }.each {
        generate(it, dir)
    }
}

// 生成对应的文件
def generate(table, dir) {

    def entityPath = "${dir.toString()}\\entity",
        servicePath = "${dir.toString()}\\service",
        repPath = "${dir.toString()}\\repository",
        repImpPath = "${dir.toString()}\\repository\\impl",
        controllerPath = "${dir.toString()}\\controller"

    mkdirs([entityPath, servicePath, repPath, repImpPath, controllerPath])

    System.out.println(table.getName())
    def entityName = javaName(table.getName(), true)
    def fields = calcFields(table)
    def basePackage = clacBasePackage(dir)

    if (isGenerate("Entity")) {
        genUTF8File(entityPath, "${entityName}.java").withPrintWriter { out -> genEntity(out, table, entityName, fields, basePackage) }
    }
    if (isGenerate("Service")) {
        genUTF8File(servicePath, "${entityName}Service.java").withPrintWriter { out -> genService(out, table, entityName, fields, basePackage) }
    }
    if (isGenerate("Repository")) {
        genUTF8File(repPath, "${entityName}Repository.java").withPrintWriter { out -> genRepository(out, table, entityName, fields, basePackage) }
    }
    if (isGenerate("RepositoryCustom")) {
        genUTF8File(repPath, "${entityName}RepositoryCustom.java").withPrintWriter { out -> genRepositoryCustom(out, entityName, basePackage) }
    }
    if (isGenerate("RepositoryImpl")) {
        genUTF8File(repImpPath, "${entityName}RepositoryImpl.java").withPrintWriter { out -> genRepositoryImpl(out, table, entityName, fields, basePackage) }
    }

}

// 是否需要被生成
def isGenerate(itemName) {
    config.generateItem.contains(itemName)
}

// 指定文件编码方式,防止中文注释乱码
def genUTF8File(dir, fileName) {
    new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(dir, fileName)), "utf-8"))
}

// 生成每个字段
def genProperty(out, field) {

    out.println ""
    out.println "\t/**"
    out.println "\t * ${field.comment}"
    out.println "\t * default value: ${field.default}"
    out.println "\t */"
    // 默认表的第一个字段为主键
    if (field.position == 1) {
        out.println "\t@Id"
    }
    out.println "\t@Column(name = \"${field.colum}\", nullable = ${!field.isNotNull}, length = ${field.len})"
    out.println "\tprivate ${field.type} ${field.name};"
}

// 生成get、get方法
def genGetSet(out, field) {

    // get
    out.println "\t"
    out.println "\tpublic ${field.type} get${field.name.substring(0, 1).toUpperCase()}${field.name.substring(1)}() {"
    out.println "\t\treturn this.${field.name};"
    out.println "\t}"

    // set
    out.println "\t"
    out.println "\tpublic void set${field.name.substring(0, 1).toUpperCase()}${field.name.substring(1)}(${field.type} ${field.name}) {"
    out.println "\t\tthis.${field.name} = ${field.name};"
    out.println "\t}"
}

// 生成实体类
def genEntity(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.entity;"
    out.println ""
    if (config.extendBaseEntity) {
        out.println "import $baseEntityPackage;"
    }
    if (config.useLombok) {
        out.println "import lombok.Data;"
        out.println ""
    }
    if (config.impSerializable) {
        out.println "import java.io.Serializable;"
        out.println ""
    }
    out.println "import javax.persistence.*;"
    out.println ""
    out.println "/**"
    out.println " * ${table.getComment()}"
    out.println " */"
    if (config.useLombok) {
        out.println "@Data"
    }
    out.println "@Entity"
    out.println "@Table(name = \"${table.getName()}\")"
    out.println "public class $entityName${config.extendBaseEntity ? " extends BaseEntity" : ""}${config.impSerializable ? " implements Serializable" : ""} {"

    if (config.extendBaseEntity) {
        fields = fields.findAll { it ->
            !baseEntityProperties.any { it1 -> it1 == it.name }
        }
    }

    fields.each() {
        genProperty(out, it)
    }

    if (!config.useLombok) {
        fields.each() {
            genGetSet(out, it)
        }
    }
    out.println "}"
}

// 生成Service
def genService(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.service;"
    out.println ""
    out.println "import ${basePackage}.repository.${entityName}Repository;"
    if (config.extendBaseService) {
        out.println "import $baseServicePackage;"
        out.println "import ${basePackage}.entity.$entityName;"
    }
    out.println "import org.springframework.stereotype.Service;"
    out.println ""
    out.println "import javax.annotation.Resource;"
    out.println ""
    out.println "@Service"
    out.println "public class ${entityName}Service${config.extendBaseService ? " extends BaseService<$entityName, ${fields[0].type}>" : ""}  {"
    out.println ""
    out.println "\t@Resource"
    out.println "\tprivate ${entityName}Repository rep;"
    out.println "}"
}

// 生成Repository
def genRepository(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.repository;"
    out.println ""
    out.println "import ${basePackage}.entity.$entityName;"
    out.println "import org.springframework.data.jpa.repository.JpaRepository;"
    out.println ""
    out.println "public interface ${entityName}Repository extends JpaRepository<$entityName, ${fields[0].type}>, ${entityName}RepositoryCustom {"
    out.println ""
    out.println "}"
}

// 生成RepositoryCustom
def genRepositoryCustom(out, entityName, basePackage) {
    out.println "package ${basePackage}.repository;"
    out.println ""
    out.println "public interface ${entityName}RepositoryCustom {"
    out.println ""
    out.println "}"
}

// 生成RepositoryImpl
def genRepositoryImpl(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.repository.impl;"
    out.println ""
    out.println "import ${basePackage}.repository.${entityName}RepositoryCustom;"
    out.println "import org.springframework.stereotype.Repository;"
    out.println ""
    out.println "import javax.persistence.EntityManager;"
    out.println "import javax.persistence.PersistenceContext;"
    out.println ""
    out.println "@Repository"
    out.println "public class ${entityName}RepositoryImpl implements ${entityName}RepositoryCustom {"
    out.println ""
    out.println "\t@PersistenceContext"
    out.println "\tprivate EntityManager em;"
    out.println "}"
}

// 生成文件夹
def mkdirs(dirs) {
    dirs.forEach {
        def f = new File(it)
        if (!f.exists()) {
            f.mkdirs()
        }
    }
}

def clacBasePackage(dir) {
    dir.toString()
            .replaceAll("^.+\\\\src\\\\main\\\\java\\\\", "")
            .replaceAll("\\\\", ".")
}

def isBaseEntityProperty(property) {
    baseEntityProperties.find { it == property } != null
}

// 转换类型
def calcFields(table) {
    DasUtil.getColumns(table).reduce([]) { fields, col ->

        def spec = Case.LOWER.apply(col.getDataType().getSpecification())
        def typeStr = typeMapping.find { p, t -> p.matcher(spec).find() }.value
        fields += [[
                           name     : javaName(col.getName(), false),
                           colum    : col.getName(),
                           type     : typeStr,
                           len      : col.getDataType().toString().replaceAll("[^\\d]", ""),
                           default  : col.getDefault(),
                           comment  : col.getComment(),
                           isNotNull: col.isNotNull(),
                           position : col.getPosition(),
//                           getDefault            : col.getDefault(),
//                           getParent             : col.getParent(),
//                           getTable              : col.getTable(),
//                           getDataType           : col.getDataType(),
//                           isNotNull             : col.isNotNull(),
//                           getWeight             : col.getWeight(),
//                           getDocumentation      : col.getDocumentation(),
//                           getTableName          : col.getTableName(),
//                           getName               : col.getName(),
//                           getLanguage           : col.getLanguage(),
//                           getTypeName           : col.getTypeName(),
//                           isDirectory           : col.isDirectory(),
//                           isValid               : col.isValid(),
//                           getComment            : col.getComment(),
//                           getText               : col.getText(),
//                           getDeclaration        : col.getDeclaration(),
//                           getPosition           : col.getPosition(),
//                           canNavigate           : col.canNavigate(),
//                           isWritable            : col.isWritable(),
//                           getIcon               : col.getIcon(),
//                           getManager            : col.getManager(),
//                           getDelegate           : col.getDelegate(),
//                           getChildren           : col.getChildren(),
//                           getKind               : col.getKind(),
//                           isCaseSensitive       : col.isCaseSensitive(),
//                           getProject            : col.getProject(),
//                           getDataSource         : col.getDataSource(),
//                           getVirtualFile        : col.getVirtualFile(),
//                           getMetaData           : col.getMetaData(),
//                           canNavigateToSource   : col.canNavigateToSource(),
//                           getDisplayOrder       : col.getDisplayOrder(),
//                           getDasParent          : col.getDasParent(),
//                           getLocationString     : col.getLocationString(),
//                           getDependences        : col.getDependences(),
//                           getBaseIcon           : col.getBaseIcon(),
//                           getNode               : col.getNode(),
//                           getTextLength         : col.getTextLength(),
//                           getFirstChild         : col.getFirstChild(),
//                           getLastChild          : col.getLastChild(),
//                           getNextSibling        : col.getNextSibling(),
//                           getTextOffset         : col.getTextOffset(),
//                           getPrevSibling        : col.getPrevSibling(),
//                           getPresentation       : col.getPresentation(),
//                           isPhysical            : col.isPhysical(),
//                           getTextRange          : col.getTextRange(),
//                           getPresentableText    : col.getPresentableText(),
//                           textToCharArray       : col.textToCharArray(),
//                           getStartOffsetInParent: col.getStartOffsetInParent(),
//                           getContext            : col.getContext(),
//                           getUseScope           : col.getUseScope(),
//                           getResolveScope       : col.getResolveScope(),
//                           getReferences         : col.getReferences(),
//                           getReference          : col.getReference(),
//                           getContainingFile     : col.getContainingFile(),
//                           getOriginalElement    : col.getOriginalElement(),
//                           getNavigationElement  : col.getNavigationElement(),
//                           getUserDataString     : col.getUserDataString(),
//                           isUserDataEmpty       : col.isUserDataEmpty(),
//                           getDbParent           : col.getDbParent(),
                   ]]

    }
}

def javaName(str, capitalize) {
    def s = str.split(/(?<=[^\p{IsLetter}])/).collect { Case.LOWER.apply(it).capitalize() }
            .join("").replaceAll(/[^\p{javaJavaIdentifierPart}]/, "_").replaceAll(/_/, "")
    capitalize || s.length() == 1 ? s : Case.LOWER.apply(s[0]) + s[1..-1]
}

下面注释的一大堆东西,就是可以获取信息的方法,有兴趣可以自己试试。

今天(2019/3/25)发现枚举类型不需要长度,调整了下生成代码,

import com.intellij.database.model.DasTable
import com.intellij.database.model.ObjectKind
import com.intellij.database.util.Case
import com.intellij.database.util.DasUtil

config = [
        impSerializable  : true,
        extendBaseEntity : true,
        extendBaseService: true,
        useLombok        : true, // 不使用会生成get、set方法

        // 不生成哪个就注释哪个
        generateItem     : [
                "Entity",
//                "Service",
//                "Repository",
//                "RepositoryCustom",
//                "RepositoryImpl",
        ]
]

baseEntityPackage = "com.yija.project.framework.base.BaseEntity"
baseServicePackage = "com.yija.project.framework.base.BaseService"
baseEntityProperties = ["id", "createDate", "lastModifiedDate", "version"]

typeMapping = [
        (~/(?i)bool|boolean|tinyint/)     : "Boolean",
        (~/(?i)bigint/)                   : "Long",
        (~/int/)                          : "Integer",
        (~/(?i)float|double|decimal|real/): "Double",
        (~/(?i)datetime|timestamp/)       : "java.util.Date",
        (~/(?i)date/)                     : "java.sql.Date",
        (~/(?i)time/)                     : "java.sql.Time",
        (~/(?i)/)                         : "String"
]

FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir ->
    SELECTION.filter {
        it instanceof DasTable && it.getKind() == ObjectKind.TABLE
    }.each {
        generate(it, dir)
    }
}

// 生成对应的文件
def generate(table, dir) {

    def entityPath = "${dir.toString()}\\entity",
        servicePath = "${dir.toString()}\\service",
        repPath = "${dir.toString()}\\repository",
        repImpPath = "${dir.toString()}\\repository\\impl",
        controllerPath = "${dir.toString()}\\controller"

    mkdirs([entityPath, servicePath, repPath, repImpPath, controllerPath])

    System.out.println(table.getName())
    def entityName = javaName(table.getName(), true)
    def fields = calcFields(table)
    def basePackage = clacBasePackage(dir)

    if (isGenerate("Entity")) {
        genUTF8File(entityPath, "${entityName}.java").withPrintWriter { out -> genEntity(out, table, entityName, fields, basePackage) }
    }
    if (isGenerate("Service")) {
        genUTF8File(servicePath, "${entityName}Service.java").withPrintWriter { out -> genService(out, table, entityName, fields, basePackage) }
    }
    if (isGenerate("Repository")) {
        genUTF8File(repPath, "${entityName}Repository.java").withPrintWriter { out -> genRepository(out, table, entityName, fields, basePackage) }
    }
    if (isGenerate("RepositoryCustom")) {
        genUTF8File(repPath, "${entityName}RepositoryCustom.java").withPrintWriter { out -> genRepositoryCustom(out, entityName, basePackage) }
    }
    if (isGenerate("RepositoryImpl")) {
        genUTF8File(repImpPath, "${entityName}RepositoryImpl.java").withPrintWriter { out -> genRepositoryImpl(out, table, entityName, fields, basePackage) }
    }

}

// 是否需要被生成
def isGenerate(itemName) {
    config.generateItem.contains(itemName)
}

// 指定文件编码方式,防止中文注释乱码
def genUTF8File(dir, fileName) {
    new PrintWriter(new OutputStreamWriter(new FileOutputStream(new File(dir, fileName)), "utf-8"))
}

// 生成每个字段
def genProperty(out, field) {

    out.println ""
    out.println "\t/**"
    out.println "\t * ${field.comment}"
    out.println "\t * default value: ${field.default}"
    out.println "\t */"
    // 默认表的第一个字段为主键
    if (field.position == 1) {
        out.println "\t@Id"
    }
    // 枚举不需要长度
    out.println "\t@Column(name = \"${field.colum}\", nullable = ${!field.isNotNull}${field.dataType == "enum" ? "" : ", length = $field.len"})"
    out.println "\tprivate ${field.type} ${field.name};"
}

// 生成get、get方法
def genGetSet(out, field) {

    // get
    out.println "\t"
    out.println "\tpublic ${field.type} get${field.name.substring(0, 1).toUpperCase()}${field.name.substring(1)}() {"
    out.println "\t\treturn this.${field.name};"
    out.println "\t}"

    // set
    out.println "\t"
    out.println "\tpublic void set${field.name.substring(0, 1).toUpperCase()}${field.name.substring(1)}(${field.type} ${field.name}) {"
    out.println "\t\tthis.${field.name} = ${field.name};"
    out.println "\t}"
}

// 生成实体类
def genEntity(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.entity;"
    out.println ""
    if (config.extendBaseEntity) {
        out.println "import $baseEntityPackage;"
    }
    if (config.useLombok) {
        out.println "import lombok.Data;"
        out.println ""
    }
    if (config.impSerializable) {
        out.println "import java.io.Serializable;"
        out.println ""
    }
    out.println "import javax.persistence.*;"
    out.println ""
    out.println "/**"
    out.println " * ${table.getComment()}"
    out.println " */"
    if (config.useLombok) {
        out.println "@Data"
    }
    out.println "@Entity"
    out.println "@Table(name = \"${table.getName()}\")"
    out.println "public class $entityName${config.extendBaseEntity ? " extends BaseEntity" : ""}${config.impSerializable ? " implements Serializable" : ""} {"

    if (config.extendBaseEntity) {
        fields = fields.findAll { it ->
            !baseEntityProperties.any { it1 -> it1 == it.name }
        }
    }

    fields.each() {
        genProperty(out, it)
    }

    if (!config.useLombok) {
        fields.each() {
            genGetSet(out, it)
        }
    }
    out.println "}"
}

// 生成Service
def genService(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.service;"
    out.println ""
    out.println "import ${basePackage}.repository.${entityName}Repository;"
    if (config.extendBaseService) {
        out.println "import $baseServicePackage;"
        out.println "import ${basePackage}.entity.$entityName;"
    }
    out.println "import org.springframework.stereotype.Service;"
    out.println ""
    out.println "import javax.annotation.Resource;"
    out.println ""
    out.println "@Service"
    out.println "public class ${entityName}Service${config.extendBaseService ? " extends BaseService<$entityName, ${fields[0].type}>" : ""}  {"
    out.println ""
    out.println "\t@Resource"
    out.println "\tprivate ${entityName}Repository rep;"
    out.println "}"
}

// 生成Repository
def genRepository(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.repository;"
    out.println ""
    out.println "import ${basePackage}.entity.$entityName;"
    out.println "import org.springframework.data.jpa.repository.JpaRepository;"
    out.println ""
    out.println "public interface ${entityName}Repository extends JpaRepository<$entityName, ${fields[0].type}>, ${entityName}RepositoryCustom {"
    out.println ""
    out.println "}"
}

// 生成RepositoryCustom
def genRepositoryCustom(out, entityName, basePackage) {
    out.println "package ${basePackage}.repository;"
    out.println ""
    out.println "public interface ${entityName}RepositoryCustom {"
    out.println ""
    out.println "}"
}

// 生成RepositoryImpl
def genRepositoryImpl(out, table, entityName, fields, basePackage) {
    out.println "package ${basePackage}.repository.impl;"
    out.println ""
    out.println "import ${basePackage}.repository.${entityName}RepositoryCustom;"
    out.println "import org.springframework.stereotype.Repository;"
    out.println ""
    out.println "import javax.persistence.EntityManager;"
    out.println "import javax.persistence.PersistenceContext;"
    out.println ""
    out.println "@Repository"
    out.println "public class ${entityName}RepositoryImpl implements ${entityName}RepositoryCustom {"
    out.println ""
    out.println "\t@PersistenceContext"
    out.println "\tprivate EntityManager em;"
    out.println "}"
}

// 生成文件夹
def mkdirs(dirs) {
    dirs.forEach {
        def f = new File(it)
        if (!f.exists()) {
            f.mkdirs()
        }
    }
}

def clacBasePackage(dir) {
    dir.toString()
            .replaceAll("^.+\\\\src\\\\main\\\\java\\\\", "")
            .replaceAll("\\\\", ".")
}

def isBaseEntityProperty(property) {
    baseEntityProperties.find { it == property } != null
}

// 转换类型
def calcFields(table) {
    DasUtil.getColumns(table).reduce([]) { fields, col ->

        def spec = Case.LOWER.apply(col.getDataType().getSpecification())
        def typeStr = typeMapping.find { p, t -> p.matcher(spec).find() }.value
        fields += [[
                           name     : javaName(col.getName(), false),
                           colum    : col.getName(),
                           type     : typeStr,
                           dataType : col.getDataType().toString().replaceAll(/\(.*\)/, "").toLowerCase(),
                           len      : col.getDataType().toString().replaceAll(/[^\d]/, ""),
                           default  : col.getDefault(),
                           comment  : col.getComment(),
                           isNotNull: col.isNotNull(),
                           position : col.getPosition(),
//                           getDefault            : col.getDefault(),
//                           getParent             : col.getParent(),
//                           getTable              : col.getTable(),
//                           getDataType           : col.getDataType(),
//                           isNotNull             : col.isNotNull(),
//                           getWeight             : col.getWeight(),
//                           getDocumentation      : col.getDocumentation(),
//                           getTableName          : col.getTableName(),
//                           getName               : col.getName(),
//                           getLanguage           : col.getLanguage(),
//                           getTypeName           : col.getTypeName(),
//                           isDirectory           : col.isDirectory(),
//                           isValid               : col.isValid(),
//                           getComment            : col.getComment(),
//                           getText               : col.getText(),
//                           getDeclaration        : col.getDeclaration(),
//                           getPosition           : col.getPosition(),
//                           canNavigate           : col.canNavigate(),
//                           isWritable            : col.isWritable(),
//                           getIcon               : col.getIcon(),
//                           getManager            : col.getManager(),
//                           getDelegate           : col.getDelegate(),
//                           getChildren           : col.getChildren(),
//                           getKind               : col.getKind(),
//                           isCaseSensitive       : col.isCaseSensitive(),
//                           getProject            : col.getProject(),
//                           getDataSource         : col.getDataSource(),
//                           getVirtualFile        : col.getVirtualFile(),
//                           getMetaData           : col.getMetaData(),
//                           canNavigateToSource   : col.canNavigateToSource(),
//                           getDisplayOrder       : col.getDisplayOrder(),
//                           getDasParent          : col.getDasParent(),
//                           getLocationString     : col.getLocationString(),
//                           getDependences        : col.getDependences(),
//                           getBaseIcon           : col.getBaseIcon(),
//                           getNode               : col.getNode(),
//                           getTextLength         : col.getTextLength(),
//                           getFirstChild         : col.getFirstChild(),
//                           getLastChild          : col.getLastChild(),
//                           getNextSibling        : col.getNextSibling(),
//                           getTextOffset         : col.getTextOffset(),
//                           getPrevSibling        : col.getPrevSibling(),
//                           getPresentation       : col.getPresentation(),
//                           isPhysical            : col.isPhysical(),
//                           getTextRange          : col.getTextRange(),
//                           getPresentableText    : col.getPresentableText(),
//                           textToCharArray       : col.textToCharArray(),
//                           getStartOffsetInParent: col.getStartOffsetInParent(),
//                           getContext            : col.getContext(),
//                           getUseScope           : col.getUseScope(),
//                           getResolveScope       : col.getResolveScope(),
//                           getReferences         : col.getReferences(),
//                           getReference          : col.getReference(),
//                           getContainingFile     : col.getContainingFile(),
//                           getOriginalElement    : col.getOriginalElement(),
//                           getNavigationElement  : col.getNavigationElement(),
//                           getUserDataString     : col.getUserDataString(),
//                           isUserDataEmpty       : col.isUserDataEmpty(),
//                           getDbParent           : col.getDbParent(),
                   ]]

    }
}

def javaName(str, capitalize) {
    def s = str.split(/(?<=[^\p{IsLetter}])/).collect { Case.LOWER.apply(it).capitalize() }
            .join("").replaceAll(/[^\p{javaJavaIdentifierPart}]/, "_").replaceAll(/_/, "")
    capitalize || s.length() == 1 ? s : Case.LOWER.apply(s[0]) + s[1..-1]
}

SpringBoot JPA 代码自动生成 其四

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,547评论 6 477
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,399评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,428评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,599评论 1 274
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,612评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,577评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,941评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,603评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,852评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,605评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,693评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,375评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,955评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,936评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,172评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 43,970评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,414评论 2 342