首页 > 其他分享 >mybatis if-else(写法)

mybatis if-else(写法)

时间:2023-04-11 23:32:40浏览次数:38  
标签:... like xxx else mybatis 写法 concat

mybatis if-else(写法)

  • mybaits 中没有else要用chose when otherwise 代替

范例

<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>

范例

<choose>
    <when test="">
        //...
    </when>
    <otherwise>
        //...
    </otherwise>
</choose>

标签:...,like,xxx,else,mybatis,写法,concat
From: https://blog.51cto.com/u_15993308/6183972

相关文章

  • SpringBoot 集成 MybatisPlus 六——ActiveRecord 增、删、改
    1向表中插入记录1.1插入所有列在创建实体对象时,指定所有字段的内容,包括ID列。@TestpublicvoidtestAddUser(){Useruser=newUser(20,"成吉思汗","男","一代天骄");booleanres=user.insert();System.out.println(res);}调用MyBatisPlus时,后台执行的......
  • Mybatis_05 注解CRUD
    Mybatis_05注解CRUD1、面向接口编程大家之前都学过面向对象编程,也学习过接口,但在真正的开发中,很多时候我们会选择面向接口编程根本原因:解耦,可拓展,提高复用,分层开发中,上层不用管具体的实现,大家都遵守共同的标准,使得开发变得容易,规范性更好在一......
  • SpringBoot 集成 MybatisPlus 五——ActiveRecord
    1什么是ActiveRecordActiveRecord(活动记录),是一种领域模型模式,特点是一个模型类对应关系型数据库中的一个表,而模型类的一个实例对应表中的一行记录。在ActiveRecord模式中,对象中既有持久存储的数据,也有针对数据的操作,ActiveRecord模式把数据增删改查的逻辑作为对象的一......
  • 整合Mybatis
    步骤:在pom.xml中导入相关jar包,注意版本号junit<dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency>mybatis<dependency><groupId>org.myb......
  • mybatispuls的代码生成
    pom文件配置 <!--https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter--><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5......
  • mybatis代码
    /*//根据id查询详情publicvoidselectById()throwsIOException{//接受参数intid=1;//现在是固定数据,以后会变成动态数据//1.获取SqlSessionFactoryStringresource="mybatis-config.xml";InputStreaminputStream=Resourc......
  • MyBatisPlus——代码生成器
    代码生成器快速生成各项代码步骤创建Generator类,并创建main方法创建代码生成器AutoGeneratorautoGenerator=newAutoGenerator();连接要生成实体类的数据库DataSourceConfigdataSource=newDataSourceConfig();dataSource.setDriverName(......
  • MyBatisPlus——DML编程控制——乐观锁
    乐观锁业务并发现象带来的问题:秒杀最后一单用于中小型项目(2000请求以下)添加一个数据库字段,使每次请求修改数据时,这个字段就加一,当有多人同时请求时,这些人同时获取到的都是相同的该字段,但当有一人完成了秒杀后字段加一,其他同时获取到的该字段就不匹配了配置步骤数据库表中......
  • spring注解整合mybatis
    引入依赖<!--mybatis-spring与mybatis使用低版本适配--><!--https://mvnrepository.com/artifact/org.mybatis/mybatis-spring--><dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version&......
  • MybatisPlus——DML编程控制——增删改
    DML编程控制id生成策略控制不同的表应用不同的id生成策略日志:自增(1,2,3,4,......)购物订单:特殊规则(FQ23948AK3843)外卖单:关联地区日期等信息(1004202003143491)关系表:可省略id......注解控制@TableId类型:属性注解位置:模型类中用于表示主键的属性定义上方作用:设置......