insert into stu(id,name) values
赞
踩
1、批量插入
- <insert id="insert" parameterType = "java.util.List">
- insert into stu(id,name)
- values
- <foreach collection="list" item = "item" separator =",">
- (#{item.id},#{item.name})
- </foreach>
- </insert>
2、判空插入
- <insert id = "insert" parameterType="Map">
- insert into stu
- <trim prefix = "(" suffix = ")" suffixOverrides = ",">
- <if test="id !=null and id !=''">id,</if>
- <if test="name !=null and name !=''">name,</if>
- create_time
- </trim>
- <trim prefix = "values(" suffix = ")" suffixOverrides=",">
- <if test="id !=null and id !=''">#{id},</if>
- <if test="name !=null and name !=''">#{name},</if>
- sysdate()
- </trim>
-
- </insert>
小技巧:在mybatis中生成插入时间可以用sysdate()函数
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。