Example之selectOneByExample方法和selectByExample的使用


1、selectOneByExample示例如下:

Example userExample = new Example(User.class);
userExample.createCriteria().andEqualTo("userName",traceabilitySlice.getCreateBy()).andEqualTo("delFlag",0);
User sendUser = userMapper.selectOneByExample(userExample);

 2、selectByExample使用示例如下:

Example example = new Example(User.class);
example.createCriteria().andEqualTo("userName", user.getUserName());
List<User> list = userMapper.selectByExample(example);

 3、Example添加查詢條件時,除了使用andEqualTo外,還可設置字段降序和日期范圍查詢:

Example example = new Example(OfficialAccout.class);
//設置排序,STAT_DATE字段為降序
example.setOrderByClause("STAT_DATE ASC");
example.createCriteria().andBetween("statDate", last, now);
List<OfficialAccout> list = officialAccoutMapper.selectByExample(example);

 當排序單個字段時的使用方法

example.setOrderByClause("user_type ASC"); 

當排序多個字段時的使用方法,中間用逗號隔開

example.setOrderByClause("user_type ASC, level DESC");

或者

example.setOrderByClause("user_type , level DESC");

 

4、設置字段升序或降序的另一種方法:

Example example = new Example(IntelDrugStore.class);
example.orderBy("createTime").desc().orderBy("updateTime").desc();

 5、andBetween的使用

Example example = new Example(PlantGrowIrrigation.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("plantGrowId", plantGrowId).andBetween("irrigationDate", DateUtil.parse(startDate), DateUtil.parse(endDate));
List<PlantGrowIrrigation> list = plantGrowIrrigationMapper.selectByExample(example);

 


免責聲明!

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



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