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>
作者:Dotnet小小秋
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
嗨,如果有问题可以加QQ:1058848735 询问的哦,技术的道路上,求知求解共同探讨