学无先后,达者为师

网站首页 java综合 正文

MyBatis中模糊查询使用CONCAT('%',#{str},'%')出错的解决_java

作者:菜还膨胀   更新时间: 2022-04-03 java综合

模糊查询使用CONCAT('%',#{str},'%')出错

原因及解决

经过我一套乱七八糟毫无思路地查找后,发现不是Mybatis的原因,原来是SQL server不支持CONCAT函数,直接用加号连接就好

MyBatis like模糊查询,CONCAT函数用法

以MySQL为例

<select id="getByPage" resultType="com.test.domain.Users" parameterType="com.test.Param">
SELECT * FROM tb_users where isdeleted=1 
<if test="name!=null and name!=''">
     AND nickname LIKE CONCAT('%', '${name}', '%')
</if>
ORDER BY createtime DESC
limit #{fromIndex},#{count}
</select>

原文链接:https://blog.csdn.net/WHUT618/article/details/103435729

栏目分类
最近更新