mybatis——逆向工程中 where (條件1)and (條件2 or 條件3 or 條件4)


where (條件1)and (條件2 or 條件3 or 條件4)

= where (條件1 and 條件2)or (條件1 and 條件3) or (條件1 and 條件4)

 

 

 結果 是這樣的 

WHERE ( birthdate between ? and ? and username like ? ) or( birthdate between ? and ? and email like ? ) or( birthdate between ? and ? and phone like ? ) 

 

 

1. 在Example中每一個criteria相當於一個括號,把里面的內容當作一個整體。

Where(userid=’1’ and name=’2’)


1
2
3
4
UserExample example = new UserExample();
UserExample.Criteria c1 = example.createCriteria();
C1.andUseridEqualTo(“1”);
C2.andNameEqualTo(“2”);

C1.andUseridEqualTo(“1”).andNameEqualTo(“2”);也可

 

2. 在criteria中沒有直接的or。

(1) where(A and B) or (C and D)

1
2
3
4
5
6
7
8
BasePointsExample.Criteria criteria1 = example.createCriteria();
           criteria1.andUseridEqualTo('11');
           criteria1.andPointnameLike(StringUtil.concatlike('22'));
  
 BasePointsExample.Criteria criteria2 = example.createCriteria();
           criteria2.andUsernameEqualTo('33');
           criteria2.andPointcontentLike(StringUtil.concatlike('44'));
 example.or(criteria2);

(2)where A and (B or C)

==>(A and B) or (A and C)

1
2
3
4
5
6
7
8
BasePointsExample.Criteria criteria1 = example.createCriteria();
      criteria1.andUseridEqualTo('11');
      criteria1.andPointnameLike(StringUtil.concatlike('22'));
  
      BasePointsExample.Criteria criteria2 = example.createCriteria();
      criteria2.andUseridEqualTo('11');
      criteria2.andPointcontentLike(StringUtil.concatlike('33'));
      example.or(criteria2);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM