MybatisPlus Wrapper 自定义条件构造器
查询条件构造器 QueryWrapper
// lt:less than 小于
// le:less than or equal to 小于等于
// eq:equal to 等于
// ne:not equal to 不等于
// ge:greater than or equal to 大于等于
// gt:greater than 大于
QueryWrapper<FormOrg> queryWrapper = new QueryWrapper<>(); queryWrapper.eq("APP_CODE", appCode); queryWrapper.in("ORG_CODE", orgList); queryWrapper.eq("APPLY_TYPE_CODE", ""); queryWrapper.le("BEGIN_DATE", startDate); queryWrapper.ge("END_DATE", startDate); queryWrapper.eq("TURN_ON_OR_NOT", "1");
List<FormOrg> list = xxxService.list(queryWrapper);
引入lambda,避免我们在代码中写类似的于 APP_CODE 的硬编码 LambdaQueryWrapper<SysUser>
LambdaQueryWrapper<SysUser> queryWrapper = new QueryWrapper<SysUser>().lambda(); // 简化写法如下 // LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(SysUser::getUserName, "admin"); List<SysUser> list = sysUserMapper.selectList(queryWrapper); System.out.println(list);
- 链式查询 LambdaQueryChainWrapper (粗体是区别,注意)
List<SysUser> list1 = new LambdaQueryChainWrapper<>(sysUserMapper) .eq(SysUser::getUserName, "admin") .list();
查询一条记录,通过id查询某条记录的详情,使用.one()
即可
SysUser sysUser = new LambdaQueryChainWrapper<>(sysUserMapper) .eq(SysUser::getId, "1") .one();
select 指定查询字段
queryWrapper.select("USER_NAME","USER_CODE");
未完,待续。。。