首页 > 数据库 >Java使用MyBatis-Plus生成动态数据库表XML配置

Java使用MyBatis-Plus生成动态数据库表XML配置

时间:2023-01-14 23:56:10浏览次数:38  
标签:XML COMMENT Java tableName filedName item Plus NULL

<update id="createSpiderTable" parameterType="com.quanchengle.app.spider.CreateSpiderTableAndTableName">
    CREATE TABLE IF NOT EXISTS ${tableName} (
    <if test="tableFields==null or tableFields.size()==0">
        `id` int NOT NULL AUTO_INCREMENT COMMENT '编号'
    </if>
    <foreach collection="tableFields" item="item" separator="">
        <if test="item.filedName != null and item.filedName !=''">
            `${item.filedName}` ${item.fieldType}
            <choose>
                <when test="item.isNotNull != null and item.isNotNull !=''">
                    NOT NULL
                </when>
            </choose>


            <choose>
                <when test="item.defaultValue != null and item.defaultValue !=''">
                    DEFAULT ${item.defaultValue}
                </when>
                <otherwise>
                </otherwise>
            </choose>
            <choose>
                <when test="item.filedComment != null and item.filedComment !=''">
                    COMMENT '${item.filedComment}'
                </when>
                <otherwise>
                    COMMENT '${item.filedName}'
                </otherwise>
            </choose>
            ,
        </if>
    </foreach>
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
</update>
<update id="alterAddSpiderTable">
    <if test="item.isExist = false and item.filedName != null and item.filedName !='' ">
        ALTER TABLE ${tableName} ADD `${item.filedName}` ${item.fieldType}
    </if>
</update>
<update id="insertSpiderTableInfo" parameterType="com.quanchengle.app.spider.ChangeSpiderTableInfo">
    INSERT INTO ${tableName}
    <foreach collection="tableFiledNames" open="(" close=")" item="item" separator=",">
        `${item.filedName}`
    </foreach>
    VALUES
    <foreach collection="tableFiledValues" item="tabItem" index="index" separator=",">
        <foreach collection="tabItem.filedValues" open="(" close=")" item="item" index="index" separator=",">
            #{item.filedValue,jdbcType=VARCHAR}
        </foreach>
    </foreach>


</update>

标签:XML,COMMENT,Java,tableName,filedName,item,Plus,NULL
From: https://www.cnblogs.com/sopcce/p/17052847.html

相关文章

  • 04.Java基础语法
    一元运算符Java基础语法一、注释、标识符、关键字注释Java中的注释有三种:​ 单行注释​ 多行注释​ 文档注释publicclassHello_World{//两个斜杠就是一个......
  • Java反射机制
    概念反射是Java的特征之一,是一种间接操作目标对象的机制在JVM运行的时候会动态加载类,对于任意一个类都能获取到该类的所有属性和方法,对于任意一个对象,都能够调用它的任意......
  • java中的基本类型
    引入我们前面使用过了输出语句System.out.println();知道了它能够输出()里的东西但是它到底能够输出一些什么东西呢,或者直奔主题它能够输出什么类型呢可以尝试一下,如果我......
  • Java JDK1.8的安装详细教程
    转载:https://www.jb51.net/article/243119.htmjdk1.8又称jdk8.0,是目前相对比较稳定的版本,不建议下载最新的jdk版本,因为最新版的jdk不稳定,在Java的学习中可能会出现各种各......
  • spark任务报错java.io.IOException: Failed to send RPC xxxxxx to xxxx:xxx, but got
    ##日志信息如下```Attemptedtogetexecutorlossreasonforexecutorid17atRPCaddress192.168.48.172:59070,butgotnoresponse.Markingasslavelost.......
  • mybatis&mybatis-plus的sql语句
    在springboot项目中,我们会使用到sql语句,要么是使用mybatis-plus底层已经写好的,要么是使用mybatis,来编写对应的sql映射文件.注意:在springboot中,只需要导入mybatis-pl......
  • 【JavaScript】使用WdatePicker.js插件限选一个时间范围(例如一个月)
    需求:公司处理的业务数据比较大,单张表就是几十上百万的。如果不加入指定的条件,指定的时间,限定条数的查。经过多张表的关联查询sql执行速度将会变得特别慢。之前限定时间都是......
  • Java集合之LinkedList源码分析
    LinkedList文章目录​​LinkedList​​​​LinkedList介绍​​​​LinkedList的方法总结​​​​LinkedList源码分析​​​​GetElement​​​​RemoveElement​​​​......
  • JavaDoc
      网址:https://docs.oracle.com/en/java/javase/17/docs/api/   在base文件夹打开,cmd然后输入下面这一行 然后base文件夹会出现很多东西,点击进去会出现bas......
  • Java基础之 Integer 类源码分析
    Integer类源码说明Java中Integer是基本数据类型int的包装类。也就是每一个Integer对象包含一个int类型的属性,是抽象类Number类的子类,位于java.lang包下。部分源码:publicfi......