加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

MyBatis常用标签大全

发布时间:2020-12-14 14:38:01 所属栏目:Java 来源:网络整理
导读:_parameter _parameter 表示当前传入的参数,如果查询的时候传入的参数只有一个,则使用 _parameter E getById(Integer id); select id="getById" parameterType="int" resultMap="BaseResultMap" SELECT * FROM 库名.表名 WHERE id = #{_parameter} /select

_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,</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常用标签大全,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读