常用mapper方法

1.insert,表中有时间字段,且字段值为当前时间,可以在mapper中完成,不用赋值
<insert id="insert" parameterType="com.dhgate.ywuser.po.Merchant">
<selectKey resultType="java.lang.Long" keyProperty="historyid" order="AFTER"> 		
INSERT INTO
<include refid="TABLE_NAME" />
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
time,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
NOW(),
</trim>
</insert>

说明:
(1)keyProperty 指向表中主键
(2)selectKey的作用为了查询主键值,作为下一个插入的ID值

你可能感兴趣的:(mybatis,insert)