AbstractWrapper:
/** * 使用构造器 条件查询 */ @Test public void selectOne() { AbstractWrapper wrapper = new QueryWrapper<>(); wrapper.eq("nick_name", "测试一下"); //区间查询 //wrapper.between("member_id",1,90); MemberInfo result = memberInfoMapper.selectOne(wrapper); System.out.println(result); }
QueryWrapper
/** * 排序查询 */ @Test public void selectOrderList() { QueryWrapper<ShippingAddress> wrapper = new QueryWrapper<>(); //根据id排序 orderByAsc:升序 orderByDesc:降序 wrapper.orderByAsc("member_id"); List<ShippingAddress> addressList = shippingAddressMapper.selectList(wrapper); addressList.forEach(System.out::println); }
/** * 模糊查询 */ @Test public void selectList() { QueryWrapper<ShippingAddress> wrapper = new QueryWrapper<>(); //模糊包含 //wrapper.like("detail_address","广东"); //右模糊查询 向左查起 wrapper.likeRight("detail_address", "广"); List<Map<String, Object>> map = shippingAddressMapper.selectMaps(wrapper); map.forEach(System.out::println); }
/** * 条件查询 */ @Test public void selectObjs() { QueryWrapper<ShippingAddress> wrapper = new QueryWrapper<>(); //查询id <100的数据 select * from shipping_address where member_id in (你的sql) wrapper.inSql("member_id", "select member_id from shipping_address where member_id<100"); List<Object> objectList = shippingAddressMapper.selectObjs(wrapper); System.out.println(objectList); }
UpdateWrapper
/** * 编辑信息 */ @Test public void update() { MemberInfo memberInfo = new MemberInfo(); UpdateWrapper updateWrapper = new UpdateWrapper(); memberInfo.setMemberId(memberInfo.getMemberId()); updateWrapper.set("nick_name", "程序图"); //updateWrapper.setSql("nick_name = '老李头'"); memberInfoMapper.update(memberInfo, updateWrapper); }
个别参数说明:
/** * eq:等于 ne: 不等于 * gt:大于 ge:大于或等于 * lt:小于 le: 小或于或等于 * like:模糊查询(包含) notLike(不包含) likeLeft:模糊左查询 likeRight:模糊右查询 * isNull:为空 isNoNull:不为空 * orderByAsc:升序 orderByDesc:降序 * between:区间查询 age between 18 and 30 */
详细文档请前往pius官网或者MyBatis-Plus v3.3.2 使用教程
https://www.bookstack.cn/read/mybatis-3.3.2/%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8.md