use of com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper in project sduoj-server by SDUOJ.
the class ProblemManageService method queryDescriptionList.
public List<ProblemDescriptionListDTO> queryDescriptionList(String problemCode, UserSessionDTO userSessionDTO) {
ProblemDO problemDO = problemDao.lambdaQuery().select(ProblemDO::getProblemId, ProblemDO::getDefaultDescriptionId, ProblemDO::getUserId).eq(ProblemDO::getProblemCode, problemCode).one();
AssertUtils.notNull(problemDO, ApiExceptionEnum.PROBLEM_NOT_FOUND);
Long defaultDescriptionId = problemDO.getDefaultDescriptionId();
LambdaQueryChainWrapper<ProblemDescriptionDO> query = problemDescriptionDao.lambdaQuery().select(ProblemDescriptionDO::getId, ProblemDescriptionDO::getIsPublic, ProblemDescriptionDO::getProblemId, ProblemDescriptionDO::getVoteNum, ProblemDescriptionDO::getUserId, ProblemDescriptionDO::getTitle);
// 题目管理员能看到所有,admin 只能看到公开/默认/自己的题面
if (!problemCommonService.isProblemManager(problemDO, userSessionDTO)) {
Long userId = Optional.ofNullable(userSessionDTO).map(UserSessionDTO::getUserId).orElse(null);
query.and(o1 -> o1.eq(ProblemDescriptionDO::getIsPublic, 1).or(o2 -> o2.eq(ProblemDescriptionDO::getIsPublic, 0).eq(ProblemDescriptionDO::getUserId, userId)).or(o3 -> o3.eq(ProblemDescriptionDO::getId, defaultDescriptionId)));
}
List<ProblemDescriptionDO> problemDescriptionDOList = query.eq(ProblemDescriptionDO::getProblemId, problemDO.getProblemId()).list();
List<ProblemDescriptionListDTO> problemDescriptionDTOList = problemDescriptionListConverter.to(problemDescriptionDOList);
problemDescriptionDTOList.forEach(o -> {
o.setProblemCode(problemCode);
o.setUsername(userClient.userIdToUsername(o.getUserId()));
});
return problemDescriptionDTOList;
}
use of com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper in project demo-SpringBoot by Max-Qiu.
the class TestLambdaQueryWrapper method testLambdaQueryChainWrapper.
/**
* 链式写法,
*/
@Test
void testLambdaQueryChainWrapper() {
// SELECT id,username,age,email FROM smp_user WHERE (age = ?)
List<User> list = new LambdaQueryChainWrapper<>(userMapper).eq(User::getAge, 18).list();
list.forEach(System.out::println);
// SELECT COUNT(*) FROM smp_user WHERE (age = ?)
// SELECT id,username,age,email,create_time FROM smp_user WHERE (age = ?) LIMIT ?
Page<User> page = new LambdaQueryChainWrapper<>(userMapper).eq(User::getAge, 18).page(new Page<>(1, 10));
System.out.println(page.getTotal());
// SELECT COUNT( * ) FROM smp_user WHERE (age = ?)
long count = new LambdaQueryChainWrapper<>(userMapper).eq(User::getAge, 18).count();
System.out.println(count);
// SELECT id,username,age,email,create_time FROM smp_user WHERE (age = ?)
User one = new LambdaQueryChainWrapper<>(userMapper).eq(User::getAge, 18).one();
System.out.println(one);
}
use of com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper in project demo-SpringBoot by Max-Qiu.
the class TestWrappers method testWrapper.
@Test
void testWrapper() {
// 创建一个空条件的查询构造器(其实用不到,条件为空的话可以直接传null,比如 userMapper.selectList(null))
QueryWrapper<User> emptyWrapper = Wrappers.emptyWrapper();
// 创建一个查询构造器(推荐用Lambda,毕竟queryWrapper.eq("username", "max")这种写String的方式看起来不咋地)
QueryWrapper<User> queryWrapper1 = Wrappers.query();
QueryWrapper<User> queryWrapper2 = Wrappers.query(new User());
// 创建一个支持Lambda语法查询构造器(推荐,详细区别见下方代码)
LambdaQueryWrapper<User> lambdaQueryWrapper1 = Wrappers.lambdaQuery();
// 如果不使用对象接收直接链式...写法,可以使用下面这种写法设置泛型
Wrappers.<User>lambdaQuery();
LambdaQueryWrapper<User> lambdaQueryWrapper3 = Wrappers.lambdaQuery(User.class);
LambdaQueryWrapper<User> lambdaQueryWrapper4 = Wrappers.lambdaQuery(new User());
// 创建一个支持Lambda语法且支持链式写法的查询构造器
LambdaQueryChainWrapper<User> lambdaQueryChainWrapper = new LambdaQueryChainWrapper<>(userMapper);
UpdateWrapper<User> updateWrapper1 = Wrappers.update();
UpdateWrapper<User> updateWrapper2 = Wrappers.update(new User());
LambdaUpdateWrapper<User> lambdaUpdateWrapper1 = Wrappers.lambdaUpdate();
LambdaUpdateWrapper<User> lambdaUpdateWrapper2 = Wrappers.lambdaUpdate(new User());
LambdaUpdateWrapper<User> lambdaUpdateWrapper3 = Wrappers.lambdaUpdate(User.class);
LambdaUpdateChainWrapper<User> lambdaUpdateChainWrapper = new LambdaUpdateChainWrapper<>(userMapper);
}
Aggregations