/** * 1. QueryWrapper 用法示例 */ ListuserList = userMapper.selectList(new QueryWrapper () .like("email", "24252") .between("age", 20, 22) .or() .eq("name", "zcx") ); System.out.println("userList:" + userList.toString()); //2、排序用法 List users = userMapper.selectList(new QueryWrapper () .eq("nick_name", "xx") .orderByAsc("age") //升序 // .orderByDesc("age") //降序 .last("limit 0,3") //last用法:在sql末尾添加sql语句,有sql注入风险 ); System.out.println("users:"+users.toString());
/** * 2. LambdaQueryWrapper 用法示例 */ LambdaQueryWrapperqueryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(UserDo::getAccount, account); queryWrapper.eq(UserDo::getIsDelete, 0); queryWrapper.like(UserDo::getName,"lk"); queryWrapper.between(UserDo::getAge,18,20); // queryWrapper.orderByAsc(UserDo::getDeptNo); UserDo user = userMapper.selectOne(queryWrapper); Integer count = userMapper.selectCount(queryWrapper);
UserDo user1 = userMapper.selectOne(new LambdaQueryWrapper() .eq(UserDo::getAccount, username));
/** * 3. 区别 * * QueryWrapper 的列名匹配使用的是 “数据库中的字段名(一般是下划线规则)” * LambdaQueryWrapper 的列名匹配使用的是“Lambda的语法,偏向于对象” * 不同写“列名”,而是使用纯java的方式,避免了拼写错误(LambdaQueryWrapper 的写法如果有错, * 则在编译期就会报错,而QueryWrapper需要运行的时候调用该方法才会报错) * 所以LambdaQueryWrapper 更优于 QueryWrapper */
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)