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年6月20日
    44
  • Image.open()_image.open函数

    Image.open()_image.open函数文章目录1导入库2图像读取3读入图片类型4通道5显示方法6相互转换Image.open()和ci2.imread()都是用来读取的图像,但在使用过程中存在一些差别。具体,可以从以下几个角度进行分析:1导入库导入的包不同。img=cv2.imread(path),这是opencv中的处理图片的函数,使用时需importcv2img=Image.open(path),这是PIL中的一个处理图片的函数,使用时需fromPILimportImage#opencv-py

    2022年10月14日
    0
  • vue详解_vuex getters

    vue详解_vuex gettersVuex是做什么的?官方解释:Vuex是一个专为Vue.js应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化。Vuex

    2022年7月31日
    6
  • Swagger注解-@ApiModel 和 @ApiModelProperty

    @ApiModel使用场景在实体类上边使用,标记类时swagger的解析类概述提供有关swagger模型的其它信息,类将在操作中用作类型时自动内省属性属性名称数据类型默认值说明valueString类名为模型提供备用名称descriptionString“”提供详细的类描述parentClass<?>parentVoid…

    2022年4月8日
    201
  • SpringBoot + mybatis 分页查询

    SpringBoot + mybatis 分页查询com.github.pagehelper.PageHelper是一款好用的开源免费的Mybatis第三方分页插件。使用的时候,只要简单配置,就可以在查询语句之后得到所需的分页信息。1:在pom.xml中引入依赖项。dependency>groupId>com.github.pagehelpergroupId>artifactId>pagehelperarti

    2022年5月5日
    52

发表回复

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

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