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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • could not lock config file_dpkg frontend lock

    could not lock config file_dpkg frontend lockUbuntu安装软件报错问题错误信息E:Couldnotgetlock/var/lib/dpkg/lock-frontend-open(11:Resourcetemporarlyunavailable)解决办法:sudorm/var/lib/dpkg/lock-frontendsudorm/var/lib/dpkg/lock

    2022年10月7日
    2
  • 渗透测试工具——Metasploit[通俗易懂]

    渗透测试工具——Metasploit[通俗易懂]Metasplout简介Metasploit是一款开源的安全漏洞检测工具,同时Metasploit是免费的工具。Metasploit核心中绝大部分有Rudy实现,一小部分由汇编和C语言实现。kali中自带MetasploitMetasploit文件结构与模块路径:/usr/share/metasploit-framework/config:MSF环境配置信息,数据库配置信息 data:后渗透模块的一些工具及payload,第三方小工具集合,用户字典等数据信息 doc

    2022年8月12日
    5
  • Java数组转list,原来是这样–有陷阱![通俗易懂]

    Java数组转list,原来是这样–有陷阱![通俗易懂]最近开发中,业务上处理,经常用到asList方法,这让我不经想起了它的很多容易让人犯错的地方或者误解的地方,所以就想抽出时间来,整理一下,和大家分享出来,深夜了,话不多说,主要以代码为主,简易的代码,你一看就知道了!大家都知道这个方法是将数组转成list,是JDK中java.util包中Arrays类的静态方法。大家使用时一定要注意(请看代码和注释,一看就明了了): Strings[]…

    2022年8月23日
    7
  • linux vim怎么退出编辑模式_centos7退出vi编辑

    linux vim怎么退出编辑模式_centos7退出vi编辑转载自:http://blog.csdn.net/u010648555/article/details/50676647初学Linux的时候,在使用vi操作时候,有时候可能进入的是一个文件夹,这样子在退出的时候很不好操作!下面总结一些vi退出命令,学习!进入编辑模式,按o进行编辑编辑结束,按ESC键跳到命令模式,然后输入退出命令::w保存文件但不退出vi编辑:w!强制保存,不退出v…

    2022年9月29日
    1
  • matlab函数之length函数「建议收藏」

    matlab函数之length函数「建议收藏」文章来源:http://blog.sina.com.cn/yadan422 在MATLAB中:size:获取数组的行数和列数length:数组长度(即行数或列数中的较大值)numel:元素总数。s=size(A),当只有一个输出参数时,返回一个行向量,该行向量的第一个元素时数组的行数,第二个元素是数组的列数。[r,c]=size(A),当有两个输出参数时,size函数将数组的行数返回…

    2022年6月12日
    43
  • 有监督学习流程图

    有监督学习流程图

    2022年5月28日
    30

发表回复

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

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