MyBatis常用标签大全
_parameter
_parameter表示当前传入的参数,如果查询的时候传入的参数只有一个,则使用_parameter
EgetById(Integerid);
<selectid="getById"parameterType="int"resultMap="BaseResultMap"> SELECT* FROM 库名.表名 WHERE id=#{_parameter} </select>
if判断
<selectid="getUsers"parameterType="int"resultType="User"> SELECTid,name,phone,emailFROMusersWHERE1=1 <iftest="_parameter!=null"> andid>#{_parameter} </if> </select>
大量重复的字段
<sqlid="HHHHH"> id,name </sql>
引用写法
<includerefid="HHHHH"/>
foreach
1、item表示集合中每一个元素进行迭代时的别名,
2、index指定一个名字,用于表示在迭代过程中,每次迭代到的位置,
3、open表示该语句以什么开始,
4、separator表示在每次进行迭代之间以什么符号作为分隔符,
5、close表示以什么结束,
<updateid="updateBatch"> <foreachitem="item"index="index"collection="list"open="" close=""separator=";"> <iftest="item.statusType.toString()=='DELETED'"> DELETEFROM库名.表名WHEREid=#{item.id} </if> <iftest="item.statusType.toString()!='DELETED'"> UPDATE库名.表名 <set> modifier=#{item.modifier,jdbcType=CHAR}, <iftest="item.account!=null"> account=#{item.account,jdbcType=VARCHAR}, </if> <iftest="item.name!=null"> name=#{item.name,jdbcType=VARCHAR}, </if> </set> where 库名.表名.id=#{item.id} </if> </foreach> </update>
set
一定要非空判断
set为空会报错
<updateid="updateFlow"> UPDATEufis.pid SET <strong><spanstyle="font-size:24px;"></span></strong><prename="code"class="html"><iftest="<prename="code"class="html"><prename="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常用标签大全,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!