鍍金池/ 問答/Java  數(shù)據(jù)庫/ mybatis example如何生成or條件的sql

mybatis example如何生成or條件的sql

我想利用mybatis的example類生成如下的sql語句:

SELECT * FROM User where nick_name like "%1502%" or real_name like "%1502%" or mobile like "%1502%"

我本來是這樣使用的:

UserExample userExample = new UserExample();
UserExample.Criteria userCriteria = userExample.createCriteria();
userExample.or().andMobileLike("%1502%");
userExample.or().andRealNameLike("%1502%");
userExample.or().andNickNameLike("%1502%");
return userService.selectByExample(userExample);

但是這樣使用并不能返回我想要的結(jié)果,它會把所有的User數(shù)據(jù)全部返回完全沒有加入or限制笑哭
clipboard.png
求大神指教

回答
編輯回答
大濕胸

試試這個?

userExample.or().orMobileLike("%1502%");
userExample.or().orRealNameLike("%1502%");
userExample.or().orNickNameLike("%1502%");
2017年5月26日 00:32