1.查询语句,where:
<resultMap id="xxx" type="xx..Student" autoMapping="false">...</resultMap>
<select id="findAll" resultMap="xxx">
select * from student
<where>
<if test="stuNo!=null and stuNo!=''">and stuNo=#{stuNo}</if>
<if test="stuName!=null and stuName!=''">and stuName like '%' #{stuName} '%'</if>
</where>
</select>
2.插入语句,trim:
<insert id="saveAttendances">
insert into tms_attendance
<trim prefix="(" suffixOverrides="," suffix=")">
<if test="at_tid != null">at_tid,</if>
<if test="at_labnum != null">at_labnum,</if>
...
</trim>
VALUES
<trim prefix="(" suffixOverrides="," suffix=")">
<if test="at_tid != null">#{at_tid},</if>
<if test="at_labnum != null">#{at_labnum},</if>
...
</trim>
</insert>
3.修改语句,trim:
<update id="editUserById" parameterType="cn.happy.entity.Smbms_user">
update smbms_user
<trim prefix="set" suffixOverrides=",">
<if test="username !=null and username !=''">userName=#{username},</if>
<if test="userpassword !=null">userPassword=#{userpassword},</if>
</trim>
where id=#{id}
</update>
4.查询语句,foreach:
<select id="findByList" resultType="Student">
select * from student
<if test="list.size>0">
WHERE stuno in
<foreach collection="list" open="(" close=")" separator="," item="myid">
#{myid}
</foreach>
</if>
</select>