说明:文中articleService为Service实例,Article article为具体实体对象,list为存储实体对象的集合,article以code属性为主键 findByCode方法为自己封装的wrapper实现的,HmPage为IPage的具体实现类
- CRUD接口
-
Service CRUD接口
- Save
articleService.saveBatch(list,3);//批量插入 每批次插入3条 3条3条的插入
- SaveOrUpdate
articleService.saveOrUpdate(article);//当数据库中已经存在改code记录时,报错 code已经存在
- Remove
//第一个删除不了 第二个和第三个删除效果是一样的 但是方法里边参数要求的是id 可以自动识别出数据库中查询出来带id属性的实体类 获取id对应值 包括getById方法 同理 articleService.removeById(article); articleService.removeById(articleService.findByCode(article.getCode())); articleService.removeById(articleService.findByCode(article.getCode()).getId());
- List
Map<String,Object> params = new HashMap<>(); params.put("type",3); params.put("company_code",2); //查询所有 articleService.list(); //根据条件查询 articleService.listByMap(params); //返回map集合 不包含空值 articleService.listMaps(); //obj数组,只有id articleService.listObjs();
- Page
//无条件翻页查询 返回值为HmPage对象 articleService.page(new HmPage()); //带筛选条件翻页查询 返回值为HmPage对象 articleService.page(new HmPage(),queryWrapper);
- Chain链式查询
//链式查询 articleService.query().eq("code", 1234567L).eq("type", 1).list();
- Save
-
Mapper CRUD接口
- Insert Delete Update Select
-
- 条件构造器
- AbstractWrapper
-
allEq
//allEq最多有四个参数,第一个参数表示是否将该条件加入到最后生成的sql语句中 默认是true //第二个参数为过滤函数,表示是否允许筛选字段传入对比条件中,用于在查询条件中再次进行过滤 //第四个参数表示是否考虑值为null的情况 默认为true 当参数的值为null的时候 最后的sql语句会有 and xx is null //第三个参数为查询条件集合,为所有重载方法中的必填项 QueryWrapper queryWrapper = new QueryWrapper(); queryWrapper.allEq(boolean condition,BiPredicate<R,V> filter,Map<R,V> params,boolean null2IsNull);
-
单一条件查询
方法 含义 sql eq 等于 key = ‘value’ ne 不等于 key <> ‘value’ gt 大于 key > value ge 大于等于 key >= value lt 小于 key < value le 小于等于 key <= value between BETWEEN 值1 AND 值2 key between value1 and value2 notBetween NOT BETWEEN 值1 AND 值2 key not between value1 and value2 like LIKE ‘%值%’ key like ‘%value%’ notLike NOT LIKE ‘%值%’ key not like ‘%value%’ likeLeft LIKE ‘%值’ key like ‘%value’ likeRight LIKE ‘值%’ key like ‘value%’ isNull IS NULL key is null isNotNull IS NOT NULL key is not null in IN(value.get(0),value.get(1),…) key in (value1,value2,value3) notIn key not in (value1,value2,value3) inSql IN(sql语句) key in (select key1 from table where key1 < 3) notInSql NOT IN (sql语句) key not in (select key1 from table where key1 < 3) grounpBy 分组 GROUNP BY 字段 grounp by key1,key2 orderByAsc ORDER BY 字段,… ASC order by key1 ASC,key2 ASC orderByDesc ORDER BY 字段,…DESC order by key1 DESC,key2 DESC orderBy ORDER BY 字段,… having HAVING (sql语句) having (sql语句) or OR 默认连接为and,or需要主动调用 or and AND and nested 正常嵌套(不带AND或者OR) nested() apply 拼接sql apply() last 无视规则直接拼接到sql最后,多次调用执行最后一次,有sql注入风险 exists EXISTS(sql语句) exists () notExists NOT EXISTS(sql语句) not exists () 1 2 3
-
- AbstractWrapper