当前位置:首页 > 开发 > 编程语言 > mybatis,Ibatis > 正文

[简单]mybatis insert语句添加动态字段

发表于: 2015-06-01   作者:53873039oycg   来源:转载   浏览:
摘要:       mysql数据库,id自增,配置如下:       <insert id="saveTestTb" useGeneratedKeys="true" keyProperty="id" parameterType=&

      mysql数据库,id自增,配置如下:

     

<insert id="saveTestTb" useGeneratedKeys="true" keyProperty="id"
		parameterType="TestTb">
		insert into
		db_ap_fgm_TestTb(id,traffic_type
		<include refid="getTestTbField" />
		)
		values(#{id},#{trafficType}
		<include refid="getTestTbValue" />
		)
	</insert>

	<sql id="getTestTbField">
		<trim prefix="," suffixOverrides=",">
			<if
				test="testA!=null and testA!='null' and testA!=''">
				TESTA,
			</if>
			<if test="level!=null and level!='null' and level!=''">
				LEVEL,
			</if>
			<if test="state!=null and state!='null' and state!=''">
				STATE,
			</if>
			<if test="description!=null and description!='null' and description!=''">
				DESCRIPTION
			</if>
		</trim>
	</sql>

	<sql id="getTestTbValue">
		<trim prefix="," suffixOverrides=",">
			<if
				test="testA!=null and testA!='null' and testA!=''">
				#{testA},
			</if>
			<if test="level!=null and level!='null' and level!=''">
				#{level},
			</if>
			<if test="state!=null and state!='null' and state!=''">
				#{state},
			</if>
			<if test="description!=null and description!='null' and description!=''">
				#{description}
			</if>
		</trim>
	</sql>

 

[简单]mybatis insert语句添加动态字段

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号