mybatis insert 空屬性用trim suffix="" suffixOverrides=","去多餘的“,”。
<sql id="UserAreaColume"> <trim suffix="" suffixOverrides=",">
<if test="id != null">
ID,
</if>
<if test="name != null">
NAME,
</if>
<if test="type != null">
AREA_TYPE,
</if>
<if test="routePoint != null">
ROUTE_POINT,
</if>
<if test="routeStart != null">
ROUTE_START,
</if>
<if test="routeEnd != null">
ROUTE_END,
</if>
<if test="heightMax != null">
HEIGHT_MAX,
</if>
<if test="heightMin != null">
HEIGHT_MIN,
</if>
<if test="desc != null">
DESCRIPTION,
</if>
</trim>
</sql>
<sql id="UserAreaValue">
<trim suffix="" suffixOverrides=",">
<if test="id != null">
#{id},
</if>
<if test="name != null">
#{name},
</if>
<if test="type != null">
#{type},
</if>
<if test="routePoint != null">
#{routePoint},
</if>
<if test="routeStart != null">
#{routeStart},
</if>
<if test="routeEnd != null">
#{routeEnd},
</if>
<if test="heightMax != null">
#{heightMax},
</if>
<if test="heightMin != null">
#{heightMin},
</if>
<if test="desc != null">
#{desc},
</if>
</trim>
</sql>
<insert id="saveUserArea" parameterType="UserArea">
<selectKey keyProperty="id" resultType="int" order="BEFORE">
select s_user_area_id_seq.nextval as value from dual
</selectKey>
insert into s_user_area (
<include refid="UserAreaColume"/>
) values (
<include refid="UserAreaValue"/>
)
</insert>
轉:http://blog.csdn.net/grhlove123/article/details/6436539/