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)
上一篇 2026年4月14日 下午5:40
下一篇 2026年4月14日 下午5:46


相关推荐

  • 从零到一搭建一个属于自己的博客系统(弎)「建议收藏」

    从零到一搭建一个属于自己的博客系统(弎)「建议收藏」前言:结合上文讲到了博客发布,本篇文章进行对于个人的信息进行一系列操作:从零到一搭建一个属于自己的博客系统(弌):从零到一搭建一个属于自己的博客系统(弌)从零到一搭建一个属于自己的博客系统(弍):从零到一搭建一个属于自己的博客系统(弍)目录:一.界面元素:二.个人中心:1.页面部分以及HTML:2.CSS:3.效果图:4.js:三.Django接口:1.修改密码(update):2.忘记密码(see):3.日志查看(seemsg):4.日志写入(usermsg):四.补充:五.换肤:一.界面元素:

    2022年10月11日
    4
  • stm32f103波形发生器_示波器波形分析

    stm32f103波形发生器_示波器波形分析摘要本设计是基于STM32F103RCT6为主控核心的数字示波器的设计。包AD转换,波形处理,LCD液晶显示模块及外围按键,完成了简单的示波器功能,可以实时采样显示波形、振幅大小和…

    2022年10月15日
    8
  • 刚刚,xAI 发布 Grok Code Fast 1 编程模型,快、便宜、免费

    刚刚,xAI 发布 Grok Code Fast 1 编程模型,快、便宜、免费

    2026年3月15日
    1
  • 用PMML实现机器学习模型的跨平台上线

    用PMML实现机器学习模型的跨平台上线在机器学习用于产品的时候,我们经常会遇到跨平台的问题。比如我们用Python基于一系列的机器学习库训练了一个模型,但是有时候其他的产品和项目想把这个模型集成进去,但是这些产品很多只支持某些特定的生产环

    2022年8月5日
    7
  • asuswrt 单臂路由_OPENWRT-KOOLSHARE软路由,一级/单臂/二级/旁软路由设置单臂路由联网教程…

    asuswrt 单臂路由_OPENWRT-KOOLSHARE软路由,一级/单臂/二级/旁软路由设置单臂路由联网教程…【此文原创】此文基于单口软路由讨论一级/单臂路由LAN:IPV4设置除192.168.1.1之外和你局域网不冲突的地址,关闭桥接接口,物理设置eth0WAN:协议改成PPPOE,物理设置eth0二级/旁路由LAN:IPV4地址设置为上级路由网段地址,关闭DHCP。IPV4网关选择上级路由的网关地址。WAN:物理设置-桥接关掉,接口选择eth0-保存并应用客户端机:设置IP地址,网关为软路由地址,I…

    2022年5月16日
    61
  • Maven中央仓库地址整理

    Maven中央仓库地址整理1 http www sonatype org nexus 私服 nexus 工具使用 2 http mvnrepositor com 推荐 3 http repo1 maven org maven2 中心服 4 http maven aliyun com nexus content groups public 阿里云 强力推荐 4 1https maven aliyun com repository public 阿里云升级后推荐地址速度更快 更稳定 5 http re

    2026年3月17日
    2

发表回复

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

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