欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

MyBatis常用标签大全

时间:2021-05-20 09:29:37|栏目:JAVA代码|点击:

_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> 

上一篇:JAVA中Integer值的范围实例代码

栏    目:JAVA代码

下一篇:利用keytools为tomcat 7配置ssl双向认证的方法

本文标题:MyBatis常用标签大全

本文地址:http://www.codeinn.net/misctech/125232.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有