Skip to content

类似JPA根据实体生成表的一个 starter 仅限于mybatis

Notifications You must be signed in to change notification settings

memoryoverflow/forward-generation-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

forward-generation-starter

类似JPA根据实体生成表的一个 starter 仅限于mybatis

排除非表中字段:可以加修饰符 transient

配置文件:.yml

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3307/test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8
    username: root
    password: tiger
    
    ## create 每次启动都会重新创建  update 进行更新
    ddl-auto: create #update,create
    

2.注解说明 (1) @EnableAutoForwardGeneration

  @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
 @Documented
 @Import(RegisterScaner.class)
 public @interface EnableAutoForwardGeneration
 {
   // 实体类所在的包路径
   String entityPackages(); 
   // 是否开启 自动生成表
   boolean  OnOff() default true;
 }

(2)@LColumn

/**
 * <br>
 * 列注解
 * @author 永健
 * @since 2019/5/7 14:37
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface LColumn
{
    /**
     * <br>
     * 列长度 String 类型的默认为
     */
    int width() default 0;

    /**
     * <br>
     * 指定数据库类型
     */
    ColumnType type() default ColumnType.FIELDTYPE;

    /**
     * <br>
     * 列是否默认为空
     */
    boolean isNull() default true;

    /**
     * <br>
     * 是否有默认值
     */
    String defaultValue() default "";

    /**
     * <br>
     * 注释
     */
    String comment() default "";
    
    /**
     * <br>
     *  当实体 String, 数据库字段对应的是,longtext 或者其它时候,需要指定好
     *  比如文章内容的 实体 String 数据库 也要 longtext 或者其它才行,指定后,
     * 对应的数据库字段类型 优先
     */
    ColumnType mapping() default ColumnType.NULL;
    

}

(3)@LIncrement

/**
 * <br>
 * 是否自增
 * @author 永健
 * @since 2019/5/7 15:01
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface LIncrement
{
    IdType type() default IdType.NONE;
}

(4) @LNotTableField 非表中字段


/**
 * <br>
 * 排除非表中字段
 * @author 永健
 * @since 2019/5/7 15:09
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface LNotTableField
{
}

(5) @LTable

/**
 * <br>
 * 实体注解 指定表名否则转下划线
 * @author 永健
 * @since 2019/5/7 15:23
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Documented
public @interface LTable
{
  String name() default "";
}

(5) @LTableId

/**
 * <br>
 * 主键注解
 * @author 永健
 * @since 2019/5/7 14:36
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
public @interface LTableId
{
    IdType type() default IdType.NONE;
}

About

类似JPA根据实体生成表的一个 starter 仅限于mybatis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages