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

xiuyangsong 2020-04-08

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

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

mybatis——逆向工程中  where (条件1)and (条件2 or 条件3 or 条件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”);

<code>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‘));
     <span> </span>example.or(criteria2);

 

相关推荐