_parameter
_parameter represents the currently passed parameter. If there is only one parameter passed during query, use _parameter
E getById(Integer id);
<select id="getById" parameterType="int" resultMap="BaseResultMap"> SELECT * FROM library name. Table name WHERE id = #{_parameter} </select>if judgment
<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>A lot of repeated fields
<sql id="HHHHH"> id,name </sql>
Quotation writing
<include refid="HHHHH"/>
foreach
1. The item represents the alias when each element in the collection is iterated.
2. Index specifies a name to represent the position to which each iteration is reached during the iteration process.
3. Open means where does the statement start?
4. The separator indicates which symbol is used as the separator between each iteration.
5. Close means what ends?
<update id="updateBatch"> <foreach item="item" index="index" collection="list" open="" close="" separator=";"> <if test="item.statusType.toString() == 'DELETED'"> DELETE FROM library name.Table name WHERE id = #{item.id} </if> <if test="item.statusType.toString() != 'DELETED'"> UPDATE library name.Table name <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 library name.table name.id =#{item.id} </if> </foreach> </update>set
Must be non-empty judgment
If set is empty, an error will be reported
<update id="updateFlow"> UPDATE ufis.pid SET <strong><span style="font-size:24px;"></span></strong><pre name="code"><if test="<pre name="code"><pre name="code"><pre name="code">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>The above is a collection of commonly used MyBatis tags introduced to you by the editor. I hope they will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!