Mybatis xml判断使用详解

6 篇文章 1 订阅

本文章只是mybatis的一些判断使用案例。

1.关于封装map使用

<!-- map封装 -->

<!--<resultMap id="UserResultMap" type="map">

    <id property="id" column="id" />

    <result property="userName" column="user_name" />

</resultMap>

<select id="getUserMap" resultMap="UserResultMap">

     select id,user_name from user_t where id = #{id}

</select>-->

2.关于case when else end的使用

<select id="findStudentAll" resultType="com.example.demo.model.Student">
    select
      a.id,
      a.name,
      (case a.sex
       when 1 then '男'
       when 0 then '女'
       else '空的'
       end
      )sex
    from student_t a
</select>

3.关于查询返回值判断问题

<select id="getById" resultType="com.example.demo.model.Student">
    select
      a.id,
      a.name,
      IF(a.sex IS NULL,'你都没性别',a.sex) sex
    from student_t a
    where id = '4'
</select>

4.字符串的拼接使用

<select id="findConcatAll" resultType="com.example.demo.model.Student">
    select
    a.id,
    a.name,
    concat('老家是',a.adress) adress
    from student_t a
</select>

5.批量添加

<!-- 新增内部号==批量插入 -->
<insert id="addBatch" parameterType="java.util.List" >
   INSERT INTO `user_base_info`
        (`user_id`, `user_code`, `real_name`, `id_card`, `sex`, `birthday`, `phone`, `email`, `create_time`)
   VALUES
        <foreach collection="list" item="item" separator=",">
           (
              #{item.userId},
              #{item.userCode},
              #{item.realName},
              #{item.idCard},
              #{item.sex},
              #{item.birthday},
              #{item.phone},
              #{item.email},
              #{item.createTime}
           )
        </foreach>
</insert>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值