方法:
部分实例:
查询数据库指定字段
queryWrapper.select("id, name, create_date");
查询数据库指定日期,忽略时分秒,日期相等即可查出
queryWrapper.apply("date_format(create_date, '%Y-%m-%d') = {0}", date);
查询两个时间点之间的数据
包含昨天在内的七天queryWrapper.le("cur_date", DateUtils.getYesterday());queryWrapper.ge("cur_date", DateUtils.getbeforeDays(DateUtils.getYesterday(), 7));betweenqueryWrapper.between("complete_time", "2021-01-01 12:00:00", "2021-03-01 12:00:00");附:获取某天的几天前的日期,年月日格式public static String getbeforeDays(String appointDay,int days) { LocalDate date = parseStringToDate(appointDay); LocalDate beforeday = date.plusDays(-days); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); return formatter.format(beforeday);}
设置 limit,通过 last()
queryWrapper.last("limit 0,1");
查询某字段包含某值的数据
queryWrapper.like("name", name);
某字段汇总值
queryWrapper.select("IFNULL(sum(quantity),0) as total");
按照某字段倒序排列
queryWrapper.orderByDesc("create_date");
按照某字段分组
queryWrapper.groupBy("gasstation_id");
或
queryWrapper.and(wrapper -> wrapper.eq("type", 1).or().eq("type", 2));
查询 id 在数据库中的值
List Ids;queryWrapper.in("id", Ids);
mapper.xml 中 like 用法
user.name like "%"#{param.name}"%"
来源地址:https://blog.csdn.net/qq_34962507/article/details/127241850