Loading

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

<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>

posted @ 2023-01-14 23:44  家秋  阅读(687)  评论(0编辑  收藏  举报