最近在工作中经常遇到一个情况:通过mybatis的
原来的语句,必须把所有字段都Set值。
<insert id="insertSettlement" parameterType="com.entity.system.settlement.Settlement">
insert into B2B_SETTLEMENT (
ID,
Deptid,
Statement_Date,
Billamount,
Ticketidlist,
Billinterest,
Totalbill,
Operatetype,
Billstatus,
Creatorid,
Create_Date,
Auditstatus,
Isonline
)
values (
#{id},
#{deptId},
#{statementDate},
#{billAmount},
#{ticketIdList},
#{billInterest},
#{totalbill},
#{operateType},
#{billStatus},
#{creatorId},
sysdate,
#{auditStatus},
#{isOnline}
)
</insert>
加上标签,不用每次把所有值都弄满。
<insert id="insert" parameterType="com.entity.tcwechat.otms.BaseBinding">
INSERT INTO BASE_BINDING
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="hc != null">
HC,
</if>
<if test="cfcity != null">
CFCITY,
</if>
<if test="ddcity != null">
DDCITY,
</if>
<if test="hbh != null">
HBH,
</if>
<if test="cw != null">
CW,
</if>
<if test="cfdate != null">
CFDATE,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="hc != null">
#{hc},
</if>
<if test="cfcity != null">
#{cfcity},
</if>
<if test="ddcity != null">
#{ddcity},
</if>
<if test="hbh != null">
#{hbh},
</if>
<if test="cw != null">
#{cw},
</if>
<if test="cfdate != null">
#{cfdate},
</if>
</trim>
</insert>
小结
工作记录,下次遇到可以用!