• actable实体建表


    总结上次的项目,因为没有甲方需求经常改表结构(需求一直挤牙膏),所以用了actable,动态建表更新表。actable现版本只支持mysql,如果是其他的数据库还是用jpa吧。具体使用如下:

    maven依赖

            <dependency>
                <groupId>com.gitee.sunchenbin.mybatis.actable</groupId>
                <artifactId>mybatis-enhance-actable</artifactId>
                <version>1.1.0.RELEASE</version>
            </dependency>
    
    		<dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>8.0.22</version>
            </dependency>
    
            <dependency>
                <groupId>com.baomidou</groupId>
                <artifactId>mybatis-plus-boot-starter</artifactId>
                <version>3.4.0</version>
            </dependency>
    

    spring集成配置

    因为工具没有交给spring托管,或者自动集成,所以需要自己配置。

    java文件配置

    @ComponentScan("com.gitee.sunchenbin.mybatis.actable.manager.*")
    @MapperScan("com.gitee.sunchenbin.mybatis.actable.dao")
    @Configuration
    public class ACTableConfig {
    }
    
    

    yaml文件配置

     * 3. 配置文件设置
     * mybatis:
     *   table:
     *     auto: update
     *   model:
     *     pack: com.stone.entity
     *   database:
     *     type: mysql
     * 添加mqpper.xml扫表路径        - classpath*:com/gitee/sunchenbin/mybatis/actable/mapping\/*\/*.xml
     *
     */
     
    

    使用

    1. MySqlCharsetConstant.java这个对象里面配置的是mysql的数据类型,这里配置的类型越多,意味着创建表时能使用的类型越多

    2. @Column.java也是一个自定义的注解,用于标记model中的字段上,作为创建表的依据如不标记,不会被扫描到,有几个属性用来设置字段名、字段类型、长度等属性的设置,详细请看代码上的注释

    3. @Table.java也是一个自定义的注解,用于标记在model对象上,有一个属性name,用于设置该model生成表后的表名,如不设置该注解,则该model不会被扫描到

    4. @Index.java是一个自定义注解,用于标记在model中的字段上,表示为该字段创建索引,有两个属性一个是设置索引名称,一个是设置索引字段,支持多字段联合索引,如果都不设置默认为当前字段创建索引

    5. @Unique.java是一个自定义注解,用于标记在model中的字段上,表示为该字段创建唯一约束,有两个属性一个是设置约束名称,一个是设置约束字段,支持多字段联合约束,如果都不设置默认为当前字段创建唯一约束

    6. @TableComment用来配置表的注释,可用来替代@Table的comment

    7. @IsKey/@IsAutoIncrement/@IsNotNull用来代替 @Column中的isKey/isAutoIncrement/isNull三个属性,当然旧的配置方式仍然是支持的

    8. @ColumnComment字段注释,用来替代@Column中的comment

    9. @DefaultValue字段默认值,用来替代@Column中的defaultValue

    10.@ColumnType字段类型,用来替代@Column中的type,取值范围MySqlTypeConstant.java中的枚举

    11.@TableCharset表字符集,用来替代@Table中的charset,取值范围MySqlCharsetConstant.java中的枚举

    12.@TableEngine表引擎类型,用来替代@Table中的engine,取值范围MySqlEngineConstant.java中的枚举

    13.支持javax.persistence包中的部分注解,用于对tk.mybatis做支持

    javax.persistence.Column         同       com.gitee.sunchenbin.mybatis.actable.annotation.Column
    javax.persistence.Column.name    同       com.gitee.sunchenbin.mybatis.actable.annotation.Column.name
    javax.persistence.Column.length  同       com.gitee.sunchenbin.mybatis.actable.annotation.Column.length
    javax.persistence.Column.scale   同       com.gitee.sunchenbin.mybatis.actable.annotation.Column.decimalLength
    javax.persistence.Table          同       com.gitee.sunchenbin.mybatis.actable.annotation.Table
    javax.persistence.Id             同       com.gitee.sunchenbin.mybatis.actable.annotation.IsKey
    

    官网文档连接

  • 相关阅读:
    megento 安装过程问题 畅想由我
    jquery更改html标签 span 文字获取 a,span,div,class对象内容 畅想由我
    Your web server is configured incorrectly. As a result, configuration files with sensitive information are accessible from the outside. Please contact 畅想由我
    Object 与 Type
    js中apply和join
    URLRewriter实现机制
    在项目中让Ajax面向对象 (一)
    浅谈javascript中Json方式与闭包式
    在项目中让Ajax面向对象 (二)
    使用JWT创建安全的ASP.NET Core Web API
  • 原文地址:https://www.cnblogs.com/theStone/p/16015948.html
Copyright © 2020-2023  润新知