mybatis使用笔记

if test标签使用:

  1.test中多个条件使用and链接
  <if test = "str != null and str !=''">

  2. 判断字符串包含使用contains函数,主要contains单个字符时要加toString函数
  <if test = "str != null and str.contains(','.toString())>

 

foreach标签使用:

  1.拼接in多个值

  <foreach collection = "list" item = "item" index = "index" open = "(" separator = "," close=")">

    #{item}

  </foreach>

  2.多个查询条件
  

  <foreach collection = "lstr.split(',')" item = "item" index = "index" open = "" separator = "or", close="">

    column like '%' || #{item} || '%'

  </foreach>

where if标签使用:

  第一个if条件不用and,若第一个条件不存在,后面if条件下的and可被where标签自动过滤

posted @ 2020-11-12 11:28  wanxiang0501  阅读(625)  评论(0编辑  收藏  举报