mybatis if语句_java中的if else语句

mybatis if语句_java中的if else语句https://www.cnblogs.com/buzheng/p/12485464.htmlMyBatis中if-elseif-else的使用有表user(id,name,state,sex,age)1、单个if-else使用。  根据状态不同进行查询  <selectid=”selectUserByState”resultType=”com.bz.model.entity.User”>SELECT…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

http://www.leftso.com/blog/765.html

 

不过有他的替代  choose,写法如下:

        <choose>
            <when test="params!=null">
                right JOIN
            </when>
            <otherwise>
                LEFT JOIN
            </otherwise>
        </choose>
 复制        <choose>
            <when test="params!=null">
                right JOIN
            </when>
            <otherwise>
                LEFT JOIN
            </otherwise>
        </choose>

以上即可实现 if else 逻辑

 

 

 

 

 

 

 

 

https://www.cnblogs.com/buzheng/p/12485464.html

 

 

 

MyBatis中if – else if – else 的使用

有表user(id, name, state, sex, age)

1、单个 if – else 使用。

  根据状态不同进行查询

  

复制代码

<select id="selectUserByState" resultType="com.bz.model.entity.User">
    SELECT
      *
    FROM
      user
    WHERE
      1=1
    <choose>
      <when test="state == 1">
        AND name = #{name1}
      </when>
      <otherwise>
        AND name = #{name2}
      </otherwise>
    </choose>
  </select>

复制代码

2、多个if -else if -else的使用。

  

复制代码

<select id="selectUserByState" resultType="com.bz.model.entity.User">
    SELECT
      *
    FROM
      user
    WHERE
      1=1
    <choose>
      <when test="state == 1">
        AND name = #{name1}
      </when>
     <when test="state == 2">
        AND name = #{name2}
      </when>
      <otherwise>
        AND name = #{name3}
      </otherwise>
    </choose>
  </select>

复制代码

 

如有不对之处希望大家指点。共同进步,谢谢!

mybatis if语句_java中的if else语句

 

 

 

 

https://www.cnblogs.com/a8457013/p/8033263.html

 

mybatis if-else(写法)

mybaits 中没有else要用chose when otherwise 代替

范例一

复制代码

<!--批量插入用户-->
<insert id="insertBusinessUserList" parameterType="java.util.List">
    insert into `business_user` (`id` , `user_type` , `user_login` )
    values
    <foreach collection="list" index="index" item="item" separator=",">
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <choose>
                <when test="item.id != null and item.id !=''">
                    #{item.id,jdbcType=CHAR},
                </when>
                <otherwise>
                    '',
                </otherwise>
            </choose>
            <choose>
                <when test="item.userType != null and item.userType !=''">
                    #{item.userType,jdbcType=VARCHAR},
                </when>
                <otherwise>
                    '',
                </otherwise>
            </choose>
        </trim>
    </foreach>
</insert>

复制代码

其中choose为一个整体 
when是if 
otherwise是else

范例二:

复制代码

<select id="selectSelective" resultMap="xxx" parameterType="xxx">
    select
    <include refid="Base_Column_List"/>
    from xxx
    where del_flag=0
    <choose>
        <when test="xxx !=null and xxx != ''">
            and xxx like concat(concat('%', #{xxx}), '%')
        </when>
        <otherwise>
            and xxx like '**%'
        </otherwise>
    </choose>
</select>

复制代码

下面就是MyBatis中的if….else…表示方法

 

复制代码

<choose>
    <when test="">
        //...
    </when>
    <otherwise>
        //...
    </otherwise>
</choose>

复制代码

 

分类: mybatis

标签: mybatis

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/189105.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • SAE J1939介绍

    SAE J1939介绍CAN协议最初由美国博世公司提出,后来SAE在CAN2.0B的基础之上提出J1939协议,该协议主要面向客车和载重货车。J1939协议对应ISO提出的七层OSI模型中的物理层、数据链路层、网络层和应用层,除了这四层,为了保证数据的准确传输和故障诊断,J1939还具有网络管理和应用层诊断。物理层对应J1939-11、J1939-15;数据链路层对应协议中的J1939-21;网络层对应协议中的

    2022年5月1日
    113
  • python strip()函数

    python strip()函数函数原型声明:s为字符串,rm为要删除的字符序列s.strip(rm)删除s字符串中开头、结尾处,位于rm删除序列的字符s.lstrip(rm)删除s字符串中开头处,位于rm删除序列的字符s.rs

    2022年7月5日
    21
  • java读取数据库_jsp怎么显示数据库数据

    java读取数据库_jsp怎么显示数据库数据importlmdbimportos,sysdefinitialize():env=lmdb.open(“lmdb_dir”)#如果没有就创建lmdb_dir目录returnenvdefinsert(env,sid,name):txn=env.begin(write=True)txn.put(str(sid).encode(),name.encode())txn.commit()defdelete(env…

    2022年9月27日
    4
  • 适用于国内的 NTP 服务器地址(windows时间同步)[通俗易懂]

    适用于国内的 NTP 服务器地址(windows时间同步)[通俗易懂]国内提供时间服务器的地址有:阿里云提供公共NTP服务,以下7个域名:time1.aliyun.comtime2.aliyun.comtime3.aliyun.comtime4.aliyun.comtime5.aliyun.comtime6.aliyun.comtime7.aliyun.comWindows服务器,或者使用ntpdate,那么可以直接使用time.pool.aliyun.com阿里云服务器的NTP服务:ntp1.aliyun.comntp2.

    2022年5月16日
    56
  • candump命令_生成dump文件命令

    candump命令_生成dump文件命令hexdump以ASCII、十进制、十六进制或八进制显示文件内容。

    2022年9月21日
    3
  • macOS tcping 检测IP端口

    macOS tcping 检测IP端口检测IP端口1,安装tcping2,检测IP端口是否被屏蔽1,安装tcping$brewsearchtcping==>Formulaetcping$brewinstalltcpingError:Thefollowingdirectoriesarenotwritablebyyouruser:/usr/local/share/man/man8Yo…

    2022年6月23日
    94

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号