码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot中mybatis使用注解进行模糊查询

时间:2018-10-04 09:59:10      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:create   out   ref   where   sel   name   记录   它的   col   

小白一枚,spring boot 2.0.5在使用mybatis进行注解模糊查询时遇到一些低级的错误,现记录下来
错误示例:
“select * from user where name like \""#{name}\"”
这个错误报Parameter index out of range (1 > number of parameters, which is 0);

经过百度查询其它的得到这条sql语句,虽然能查出来,但是是全部数据都查出来了
“select * from user where name like ‘%’ || ‘#{name}‘ || ‘%‘”

然后用google查到正确的mybatis注解模糊查询
select * from user where name like CONCAT(‘%‘,#{name},‘%‘);

Mybatis真能锻炼sql语言能力,一下是完整示例
@Select("select * from user where name like CONCAT(‘%‘,#{name},‘%‘)")br/>@Results({
@Result(column = "create_time",property = "createTime")
})
List<User> likeSelectUser(String name);

spring boot中mybatis使用注解进行模糊查询

标签:create   out   ref   where   sel   name   记录   它的   col   

原文地址:http://blog.51cto.com/3316448/2292349

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!