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


相关推荐

  • pycharm 2022.01.13激活码_最新在线免费激活2022.02.24

    (pycharm 2022.01.13激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html2KLKA7BQFO-eyJsaWNlbnNlSWQi…

    2022年4月1日
    78
  • Buildroot 用户手册 (中文)

    Buildroot 用户手册 (中文)文章目录I.Gettingstarted1.AboutBuildroot2.Systemrequirements2.1.Mandatorypackages2.2.Optionalpackages3.GettingBuildroot4.Buildrootquickstart4.1configuration4.2build5.CommunityresourcesII.Userguide6.Buildrootconfiguration6.1.Cross-compil

    2022年10月20日
    2
  • af-s af-f_read fpdma queued

    af-s af-f_read fpdma queued1.PDAF驱动功能验证1.1pdaflog设置log设置,打开AF(8),State(2),Sensor(2)的logCT30P:/#cat/vendor/etc/camera/camxoverridesettings.txtoverrideLogLevels=0x3FlogWarningMask=0x08000202logInfoMask=0x08000202logVerboseMask=0x08000202enable3ADebugData=TRUEdumpSens

    2025年9月27日
    2
  • 雷塞控制器SMC304简单介绍

    雷塞控制器SMC304简单介绍                           SMC304运动控制器                                                                                            2018.3产品概述:        SMC304控制器(BASIC版):基于嵌入式…

    2022年6月3日
    58
  • gg修改器怎么编写lua脚本

    gg修改器怎么编写lua脚本gg修改器怎么编写lua脚本,gg修改器编写Lua脚本的例子从搜索冻结值的数10.搜索前7次的结果被冻结为8的值。gg.searchNumber(’10’,gg.TYPE_DWORD)localt=gg.getResults(7)fori,vinipairs(t)dot[i].value=’8’t[i].freeze=trueendgg.a…

    2025年9月15日
    7
  • json字符串转换成对象有哪几种方法_jsonstring转对象

    json字符串转换成对象有哪几种方法_jsonstring转对象1.将json字符串转化为json对象a.方案一:jquery自带的$.parseJSON函数&amp;lt;script&amp;gt;varjsonstr=&quot;{\&quot;id\&quot;:\&quot;1\&quot;,\&quot;name\&quot;:\&quot;jack\&quot;}&quot;;varobj=$.parseJSON(jsonstr);&a

    2022年9月1日
    5

发表回复

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

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