_parameter
_parameter 表示當前傳入的參數,如果查詢的時候傳入的參數只有一個,則使用 _parameter
E getById(Integer id);
<select id="getById" parameterType="int" resultMap="BaseResultMap"> SELECT * FROM 庫名.表名 WHERE id = #{_parameter} </select> if判斷
<select id="getUsers" parameterType="int" resultType="User"> SELECT id, name, phone, email FROM users WHERE 1=1 <if test="_parameter != null"> and id > #{_parameter} </if> </select> 大量重復的字段
<sql id="HHHHH"> id,name </sql>
引用寫法
<include refid="HHHHH"/>
foreach
1、item表示集合中每一個元素進行迭代時的別名,
2、index指定一個名字,用于表示在迭代過程中,每次迭代到的位置,
3、open表示該語句以什么開始,
4、separator表示在每次進行迭代之間以什么符號作為分隔符,
5、close表示以什么結束,
<update id="updateBatch"> <foreach item="item" index="index" collection="list" open="" close="" separator=";"> <if test="item.statusType.toString() == 'DELETED'"> DELETE FROM 庫名.表名 WHERE id = #{item.id} </if> <if test="item.statusType.toString() != 'DELETED'"> UPDATE 庫名.表名 <set> modifier = #{item.modifier,jdbcType=CHAR}, <if test="item.account != null"> account = #{item.account,jdbcType=VARCHAR}, </if> <if test="item.name != null"> name = #{item.name,jdbcType=VARCHAR}, </if> </set> where 庫名.表名.id =#{item.id} </if> </foreach> </update> set
一定要非空判斷
set為空會報錯
<update id="updateFlow"> UPDATE ufis.pid SET <strong><span style="font-size:24px;"></span></strong><pre name="code" class="html"><if test="<pre name="code" class="html"><pre name="code" class="html">used_flow != null"></pre> <pre></pre> <pre></pre> <pre></pre> <p></p> <pre></pre> <pre></pre> used_flow = used_flow + #{flow},<br> </if><br> change_flow_time =#{changeFlowTime}WHEREid = #{id}</update> <pre></pre> <br> <br> <p></p> </pre></pre> 以上所述是小編給大家介紹的MyBatis常用標簽大全,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答