首页 > 其他 > 详细

mybatis-xml常用写法

时间:2021-04-23 00:35:45      阅读:18      评论:0      收藏:0      [点我收藏+]

批量插入

<insert id="batchInsert" parameterType="java.util.List">
  insert into table_name (name,age,high,status,create_time,update_time)
  values
     <foreach collection="list" item="e" index="index" separator=",">
       (
        #{e.name},
        #{e.age},
        #{e.high},
        #{e.status},       
        #{e.createTime},
        #{e.updateTime}
       )
    </foreach>
</insert>

 判断String类型字段并模糊查询

<if test="name != null and name != ‘‘">
     AND name LIKE CONCAT(‘%‘,#{name},‘%‘)
</if>

判断数值类型字段并精确查询,不需要加!=‘‘

<if test="port != null">
   AND port = #{port}
</if>

单个字段的多值查询

<select id="findByIds" resultMap="xxxResultMap">
    select * from table_name where id in
    <foreach collection="ids" item="id" open="(" close=")" separator=",">
       #{id}
    </foreach>
</select>

 

mybatis-xml常用写法

原文:https://www.cnblogs.com/yb38156/p/14690023.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!