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


相关推荐

  • 有极性电容和无极性电容的区别_非极性电容

    有极性电容和无极性电容的区别_非极性电容有极性电容与无极性电容的概述有极性电容与无极性电容的概述有极性电容的识别有极性电容于无极性电容的区别网友见解有极性电容与无极性电容的概述理想的电容,本来是没有极性的。但是在实际中,为了获得大容量,就使用了某些特殊的材料和结构,这就导致了实际的电容有些是有极性的。常见的有极性电容有铝电解电容,钽电解电容等。电解电容一般是容量相对比较大的。如果要做一个大容量的无极性电容,就没那…

    2022年8月22日
    4
  • leetcode 回溯算法_java生成带括号的数学题

    leetcode 回溯算法_java生成带括号的数学题原题链接数字 n 代表生成括号的对数,请你设计一个函数,用于能够生成所有可能的并且 有效的 括号组合。示例 1:输入:n = 3输出:[“((()))”,”(()())”,”(())()”,”()(())”,”()()()”]示例 2:输入:n = 1输出:[“()”] 提示:1 <= n <= 8题解回溯class Solution {public: vector<string>res; string t = “”; voi

    2022年8月9日
    2
  • myisam和innodb 删除一条记录后,再次添加后,最大记录值

    myisam和innodb 删除一条记录后,再次添加后,最大记录值

    2021年11月6日
    39
  • Pytorch-DataLoader的使用

    Pytorch-DataLoader的使用原文连接:http://chenhao.space/post/d313d236.htmlpytorch-DataLoader的使用importtorchimporttorch.utils.dataasData#[1,1,1]相当于一句话的wordembedding,这个tensor中含有三句话x=torch.tensor([[1,1,1],[2,2,2…

    2022年5月14日
    34
  • 初学者java编程软件_编写python的软件

    初学者java编程软件_编写python的软件初学者刚刚入门学习需要用到一些开发工具,初学Java一般从控制台应用程序开发开始的,在cmd下调试,为你的电脑搭建好开发环境,需要在网站上下载JDK,安装完成后调试成功就可以开始写你的Java程序了。1.IDEAJava编程软件业界最好的Java开发工具之一,支持常见的智能补全、语法提示、代码高亮等基本功能。除此之外,还支持代码审查、代码重构、CSV整合、JUnit、GUI设计等高级功能,集成了Maven和Gradle构建工具,项目管理更加方便,因此使用的公司和…

    2022年9月23日
    0
  • idea 2021.5.3过期后怎么输激活码[在线序列号]

    idea 2021.5.3过期后怎么输激活码[在线序列号],https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月20日
    73

发表回复

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

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