当前位置:主页 > 软件编程 > JAVA代码 >

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

时间:2022-02-26 09:50:12 | 栏目: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>

您可能感兴趣的文章:

相关文章