smartnews / jpa-entity-generator

Lombok-wired JPA entity source code generator, Gradle and Maven supported.
MIT License
211 stars 72 forks source link

Would you please add the length of the column to the @Column annotation #28

Open Adrninistrator opened 5 years ago

Adrninistrator commented 5 years ago

In the generated code,there is no length property in @Column annotation, the length of columns in the automatic generated database tables is the default value 255.

I found the below code, it may works (https://my.oschina.net/zhanglikun/blog/148633/print) :

String type = columnType.toLowerCase() ;
        String propertyType = null ;
        if(StringUtils.startsWith(type, "int")) {               // int/long
            columnSize = NumberUtils.toInt(StringUtils.substring(type, StringUtils.indexOf(type, "(") + 1 ,StringUtils.indexOf(type, ")"))) ;
            if(columnSize <= 4)propertyType = "Integer" ;
            else propertyType = "Long" ;
        } else if(StringUtils.startsWith(type, "bigint")) {     // long 
            propertyType = "Long" ;
        } else if(StringUtils.startsWith(type, "double")) {     // double
            propertyType = "Double" ;
        } else if(StringUtils.startsWith(type, "float")) {      // float
            propertyType = "Float" ;
        } else if(StringUtils.startsWith(type, "varchar")) {    // String
            columnSize = NumberUtils.toInt(StringUtils.substring(type, StringUtils.indexOf(type, "(") + 1 ,StringUtils.indexOf(type, ")"))) ;
            propertyType = "String" ;
        } else if(StringUtils.startsWith(type, "char")) {       // String
            columnSize = NumberUtils.toInt(StringUtils.substring(type, StringUtils.indexOf(type, "(") + 1 ,StringUtils.indexOf(type, ")"))) ;
            propertyType = "String" ;
        } else if(StringUtils.startsWith(type, "text")) {       // String
            propertyType = "String" ;
        } else if(StringUtils.startsWith(type, "date")) {       // date
            propertyType = "java.util.Date" ;
        } else if(StringUtils.startsWith(type, "datetime")) {   // date
            propertyType = "java.util.Date" ;
        } else if(StringUtils.startsWith(type, "timestamp")) {  // date 
            propertyType = "java.util.Date" ;

Would please add the length property. Thanks!

seratch commented 4 years ago

This is just my opinion, but having some features to allow 3rd parties to create their own extensions may be fine for supporting this type of enhancements. 🤔

Adrninistrator commented 3 years ago

You can see my fork: https://github.com/Adrninistrator/jpa-entity-generator-enhance ^_^

pierrickrouxel commented 1 year ago

I fixed this issue with PR #42 Hope it will be merged soon.

BKBuEGmbH commented 8 months ago

@pierrickrouxel I hope your three PRs get merged soon. I like the project as ist fits the way I want to write JPA entities.