How to use Like Operator with (%) in MyBatis?

3,087 views
Skip to first unread message

vsk

unread,
Mar 6, 2012, 7:23:19 AM3/6/12
to mybatis-user
I want to achieve Select * from patient where last_name like '%john%'
with mybatis 3.0.

I am using the following code but somehow doesn't seam to work as
expected and gets all the records.
select * from patient where last_name like '%'|| #{lastName} ||'%'.

Anyone aware of the solution?

Regards,
Sk

Larry Meadors

unread,
Mar 6, 2012, 9:11:24 AM3/6/12
to mybati...@googlegroups.com
That should work - turn on logging and see what the SQL being executed
looks like.

Filipe Sousa

unread,
Mar 6, 2012, 9:29:11 AM3/6/12
to mybati...@googlegroups.com
You can always call my_select_method("%" + lastName + "%")

Benoît

unread,
Mar 6, 2012, 9:51:41 AM3/6/12
to mybatis-user
Alternatively add the '%' chars to your property just before calling
the mapper.
Reply all
Reply to author
Forward
0 new messages