Mybatis中使用@Select注解进行模糊查询,使用concat关键字
一、正确的方式:
@Select("select * from `test`.loan_link where link_name like concat('%',#{linkName},'%') order by add_time desc")
List<LoanLinkEntity> queryByLinkName(@Param("linkName") String linkName);
运行正常,能够模糊查询
二、采用下面的方式报错
@Select("select * from `test`.loan_link where link_name like '%#{linkName}%' order by add_time desc")
List<LoanLinkEntity> queryByLinkName(@Param("linkName") String linkName);
运行结果:
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).