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


相关推荐

  • 电子琴入门教程视频电子琴简谱

    电子琴入门教程视频电子琴简谱电子琴入门教程视频电子琴简谱9套少儿电子琴教程1,儿童电子琴启蒙(上下集)2,儿童专用-简谱五线谱视频教程3,电子琴启蒙视频教程4,儿童电子琴启蒙-全套教程5,少儿电子琴教程6,少儿电子琴入门7,少年儿童电子琴初级、中级、高级教程8,经典儿童歌曲歌谱大全9,儿童电子琴启蒙文档网盘链接:链接:https://pan.baidu.com/s/1PpguBcJOeS82SzELRyG9PA提取码:love领到了给个赞鼓励下哦~…

    2022年8月29日
    7
  • Baidu与Google地图API初探

    Baidu与Google地图API初探

    2021年12月1日
    44
  • 第一天来到新公司的volg (ETL开发工程师)[通俗易懂]

    第一天来到新公司的volg (ETL开发工程师)[通俗易懂]第一天来到新公司的volg(ETL开发工程师)新的改变首先自我介绍一下,我是一名刚刚大学毕业的程序猿,在大学完了两年,到最后大三一年才开始认真的去学习编程的各种知识,开源框架,看视频代码。现在是大数据时代,我也想跟着潮流,所以我第一份工作就选择了ETL开发,为以后大数据开发做基础铺垫,毕竟现在大数据开发都没公司直接招实习生或刚刚毕业的人。新的工作先说一下今天来公司吧,上午大概就是9点到…

    2022年6月6日
    80
  • 异步发送邮件完整示例

    异步发送邮件完整示例

    2022年2月13日
    45
  • Python科学计算之Pandas[通俗易懂]

    Python科学计算之Pandas[通俗易懂]Reference: http://mp.weixin.qq.com/s?src=3&timestamp=1474979163&ver=1&signature=wnZ

    2022年7月5日
    25
  • LabVIEW图像灰度分析与变换(基础篇—4)

    LabVIEW图像灰度分析与变换(基础篇—4)图像分析是将图像的像素灰度统计和测量技术结合,使机器可以理解图像内容,并提取特征信息以实现智能检测目的的学科。图像分析更侧重于对图像内容的分析、解释和识别。

    2022年6月16日
    58

发表回复

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

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