SpringBoot JPA 代碼自動(dòng)生成 其三

之前說(shuō)過(guò)怎么生成,可以參考這里可以一鍵生成entityservice递览、repository類了晃酒。

這個(gè)是對(duì)生成的內(nèi)容進(jìn)行擴(kuò)展,在寫一些基礎(chǔ)、公共的組件時(shí),不太希望使用lombok注解,反而需要最原始的get殴泰、set方法,這個(gè)就是加上可以生成get浮驳、set方法的配置悍汛。順便加上了注釋。

先看看新的實(shí)體類

  • 不使用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;

    /**
     * 生成時(shí)間
     * 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;

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

來(lái)看看Groovy內(nèi)容

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, // 不使用會(huì)生成get抹恳、set方法

        // 不生成哪個(gè)就注釋哪個(gè)
        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)
    }
}

// 生成對(duì)應(yīng)的文件
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"))
}

// 生成每個(gè)字段
def genProperty(out, field) {

    out.println ""
    out.println "\t/**"
    out.println "\t * ${field.comment}"
    out.println "\t * default value: ${field.default}"
    out.println "\t */"
    // 默認(rèn)表的第一個(gè)字段為主鍵
    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}"
}

// 生成實(shí)體類
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
}

// 轉(zhuǎn)換類型
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)發(fā)現(xiàn)枚舉類型不需要長(zhǎng)度瓶蚂,調(diào)整了下生成代碼糖埋,

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, // 不使用會(huì)生成get、set方法

        // 不生成哪個(gè)就注釋哪個(gè)
        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)
    }
}

// 生成對(duì)應(yīng)的文件
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"))
}

// 生成每個(gè)字段
def genProperty(out, field) {

    out.println ""
    out.println "\t/**"
    out.println "\t * ${field.comment}"
    out.println "\t * default value: ${field.default}"
    out.println "\t */"
    // 默認(rèn)表的第一個(gè)字段為主鍵
    if (field.position == 1) {
        out.println "\t@Id"
    }
    // 枚舉不需要長(zhǎng)度
    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}"
}

// 生成實(shí)體類
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
}

// 轉(zhuǎn)換類型
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 代碼自動(dòng)生成 其四

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市杭攻,隨后出現(xiàn)的幾起案子祟敛,更是在濱河造成了極大的恐慌,老刑警劉巖兆解,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件馆铁,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡锅睛,警方通過(guò)查閱死者的電腦和手機(jī)埠巨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門历谍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人辣垒,你說(shuō)我怎么就攤上這事望侈。” “怎么了勋桶?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵脱衙,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我哥遮,道長(zhǎng)岂丘,這世上最難降的妖魔是什么陵究? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任眠饮,我火速辦了婚禮,結(jié)果婚禮上铜邮,老公的妹妹穿的比我還像新娘仪召。我一直安慰自己,他們只是感情好松蒜,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布扔茅。 她就那樣靜靜地躺著,像睡著了一般秸苗。 火紅的嫁衣襯著肌膚如雪召娜。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天惊楼,我揣著相機(jī)與錄音玖瘸,去河邊找鬼。 笑死檀咙,一個(gè)胖子當(dāng)著我的面吹牛雅倒,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播弧可,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼蔑匣,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了棕诵?” 一聲冷哼從身側(cè)響起裁良,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎校套,沒想到半個(gè)月后价脾,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡搔确,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年彼棍,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了灭忠。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡座硕,死狀恐怖弛作,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情华匾,我是刑警寧澤映琳,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站蜘拉,受9級(jí)特大地震影響萨西,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜旭旭,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一谎脯、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧持寄,春花似錦源梭、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至模庐,卻和暖如春烛愧,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背掂碱。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工怜姿, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人顶吮。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓社牲,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親悴了。 傳聞我的和親對(duì)象是個(gè)殘疾皇子搏恤,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354