1、首先定义一个sql标签,一定要定义唯一id<sql id="Base_Column_List" >name,age</sql>
2、然后通过id引用
<select id="selectAll">
select
<include refid="Base_Column_List" />
from student
</select>
这个<include refid="Base_Column_List" />会自动把上面的代码贴过来。
<trim prefix="(" suffix=")" suffixOverrides="," >
</trim>
3.<trim prefix="" suffix="" suffixOverrides="" prefixOverrides="">
<insert id="insertSelective" parameterType="com.dearbinge.data.pojo.Security" > <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. --> insert into t_security <trim prefix="(" suffix=")" suffixOverrides="," > <if test="fSecuritykey != null" > f_SecurityKey, </if> <if test="fSecurityvalue != null" > f_SecurityValue, </if> <if test="fMerchantid != null" > f_MerchantId, </if> <if test="fTag != null" > f_Tag, </if> <if test="fIsdelete != null" > f_IsDelete, </if> <if test="fCreateuser != null" > f_CreateUser, </if> <if test="fCreatetime != null" > f_CreateTime, </if> <if test="fUpdateuser != null" > f_UpdateUser, </if> <if test="fUpdatetime != null" > f_UpdateTime, </if> <if test="fRemark != null" > f_Remark, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides="," > <if test="fSecuritykey != null" > #{fSecuritykey,jdbcType=VARCHAR}, </if> <if test="fSecurityvalue != null" > #{fSecurityvalue,jdbcType=VARCHAR}, </if> <if test="fMerchantid != null" > #{fMerchantid,jdbcType=VARCHAR}, </if> <if test="fTag != null" > #{fTag,jdbcType=VARCHAR}, </if> <if test="fIsdelete != null" > #{fIsdelete,jdbcType=INTEGER}, </if> <if test="fCreateuser != null" > #{fCreateuser,jdbcType=VARCHAR}, </if> <if test="fCreatetime != null" > #{fCreatetime,jdbcType=DATE}, </if> <if test="fUpdateuser != null" > #{fUpdateuser,jdbcType=VARCHAR}, </if> <if test="fUpdatetime != null" > #{fUpdatetime,jdbcType=DATE}, </if> <if test="fRemark != null" > #{fRemark,jdbcType=VARCHAR}, </if> </trim> </insert>
</trim>
prefix:在trim标签内sql语句加上前缀。
suffix:在trim标签内sql语句加上后缀。
suffixOverrides:指定去除多余的后缀内容,如:suffixOverrides=",",去除trim标签内sql语句多余的后缀","。
prefixOverrides:指定去除多余的前缀内容