tk.mybatis的Weekend简单用法,对比Example
- 其中NotifyUserRelation为实体类
//Example的写法如下(都是按照三个and条件查询记录条数)
// Example example = new Example(NotifyUserRelation.class);
// Example.Criteria criteria = example.createCriteria();
// criteria.andEqualTo("isRead", 0);
// criteria.andEqualTo("userId", userId);
// criteria.andEqualTo("delFlag", 1);
// int count = userRelationMapper.selectCountByExample(example);
//Weekend写法,其实这个是类似上面的Example的
Weekend<NotifyUserRelation> weekend = new Weekend<>(NotifyUserRelation.class);
//这个类似上面的Example.Criteria
WeekendCriteria<NotifyUserRelation, Object> weekendCriteria = weekend.weekendCriteria();
//这样写比上面更简洁,最重要的是,上面是字符串形式,
//当实体类改名,上面的写法不易查找错误,下面的就会立即报错,很快就可以定位要修改的点
weekendCriteria.andEqualTo(NotifyUserRelation::getIsRead, 0)
.andEqualTo(NotifyUserRelation::getUserId, userId)
.andEqualTo(NotifyUserRelation::getDelFlag, 1);
int count = userRelationMapper.selectCountByExample(weekend);
return count;