mybatis example/criteria and or

2018-03-14  本文已影响0人  hisenyuan

秉着能不自己在xml里面写sql就不写的原则,今天新学习了一个姿势。
利用 example 完成and or的查询

public List<SmsCountry> queryCountryName() {
SmsCountryExample example = new SmsCountryExample();
Criteria criteria = example.createCriteria();
//拼接and条件,如果有多个,可以直接在后面连着写
criteria.andIdIsNotNull().andNameIsNotNull();
//拼接or条件,如果有多个or必须这样写,连着写不行
example.or().andIdEqualTo(1);
example.or().andIdEqualTo(2);
return smsCountryMapper.selectByExample(example);
}

上一篇下一篇

猜你喜欢

热点阅读