跳到主要内容

表达式函数

1.6.2+版本后 参数in查询、拼接、模糊均需要使用函数。

1. DaoFormat.in

  • 需要使用表达式${DaoFormat.in('${参数名称}')}来实现
  • 值格式说明${参数名称}的值格式是逗号分割,如 '男,女'
  • 字符串类型:${参数名称}通过单引号引起来
  • 反回类型:字符串 '男','女'

  • 效果展示

  • 代码示例
select * from demo where sex in(${DaoFormat.in('${sex}')})

2. DaoFormat.inNumber

  • 需要使用表达式${DaoFormat.inNumber('${参数名称}')}来实现
  • 值格式说明${参数名称}的值格式是逗号分割,如 '21,22'
  • 字符串类型:${参数名称}通过单引号引起来
  • 反回类型:数值 21, 22

  • 效果展示
  • 代码示例
select * from demo where age in(${DaoFormat.inNumber('${age}')})

3. 拼接查询

  • 使用 ${DaoFormat.concat('${参数名称}',' 00:00:00')}
  • 返回类型:字符串

  • 效果展示
  • 代码示例
select * from demo where create_time between '${DaoFormat.concat('${beginTime}',' 00:00:','00')}' and '${DaoFormat.concat('${endTime}',' 23:59:59')}'

4. like查询

  • 使用sql的自带函数concat
  • 返回类型:字符串

  • 效果展示

  • 代码示例
select * from demo where 1=1
<#if name?? && name ?length gt 0>
and name like concat('%','${name}','%')
</#if>