这是利用mybatis-plus写的一个代码,但是like之后总多一个',(单引号)
<update id="updateDaily" >
<bind name="likeLeft" value="name+'%'"/>
update province_cases
set value=value+#{add},cure=cure+#{cure},death=death+#{death},add=#{add}
<if test="name != '' and name != null">
where province_cases.name like #{likeLeft}
</if>
</update>
==> Preparing: update province_cases set value=value+?,cure=cure+?,death=death+?,add=? where province_cases.name like ?
==> Parameters: 3, 3(Long), 3, 3, 山东%(String)
但是之后又出现了:
[dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException:
** where province_cases.name like '山东%'' at line 2**
我试过在like之后直接添加#{name},或者字符串拼接,但是最后都会有个单引号
有经验的程序员能说一下怎么改正吗?
你这明显不是多了个单引号,是少了个单引号
在sql中,字符串必须单引号包裹住
试用cancat
concat('%',?,'%')
传进去的参数不要再带%