当前位置: 代码迷 >> 综合 >> 基于动态sql的模糊查询
  详细解决方案

基于动态sql的模糊查询

热度:39   发布时间:2023-09-18 19:40:28.0

模糊查询用户名为username的数据记录,通过id进行升序/降序 排列 并进行分页显示 每页5条记录。

 

select   id,username password...

from 

table_name

<where>

<if test="username !=null and username !='' " >

username like concat("%",#{username},"%");

</if>

</where>

order by id  desc/asc

limit   0, 5 

 

如果中间的where字句出现在其他sql中,可以通过sql标签进行提取重用

 

<sql id="query"> 

<where>

<if test="username !=null and username !='' " >

username like concat("%",#{username},"%");

</if>

</where>

</sql>

 

from 

table_name

<include refid="query"></include>

order by id  desc/asc

limit   0, 5 

 

  相关解决方案