实体包装器,用于处理 sql 拼接,排序,实体参数查询
进行详细拼接解析:
拼接 sql 方式 一@Testpublic void testTSQL11() { /* * 实体带查询使用方法 输出看结果 */ EntityWrapper<User> ew = new EntityWrapper<User>(); ew.setEntity(new User(1)); ew.where("user_name={0}", "'zhangsan'").and("id=1") .orNew("user_status={0}", "0").or("status=1") .notLike("user_nickname", "notvalue") .andNew("new=xx").like("hhh", "ddd") .andNew("pwd=11").isNotNull("n1,n2").isNull("n3") .groupBy("x1").groupBy("x2,x3") .having("x1=11").having("x3=433") .orderBy("dd").orderBy("d1,d2"); System.out.println(ew.getSqlSegment());} 拼接 sql 方式 二int buyCount = selectCount(Condition.create() .setSqlSelect("sum(quantity)") .isNull("order_id") .eq("user_id", 1) .eq("type", 1) .in("status", new Integer[]{0, 1}) .eq("product_id", 1) .between("created_time", startDate, currentDate) .eq("weal", 1)); 自定义 SQL 方法如何使用 Wrappermapper java 接口方法List<User> selectMyPage(RowBounds rowBounds, @Param("ew") Wrapper<T> wrapper);mapper xml 定义<select id="selectMyPage" resultType="User"> SELECT * FROM user <where> ${ew.sqlSegment} </where></select> 常用词解释:where WHERE 语句,拼接 + WHERE 条件and AND 语句,拼接 + AND 字段=值andNew AND 语句,拼接 + AND (字段=值) (新的括号)or OR 语句,拼接 + OR 字段=值orNew OR 语句,拼接 + OR (字段=值)eq 等于=allEq 基于 map 内容等于=ne 不等于<>gt 大于>ge 大于等于>=lt 小于<le 小于等于<=like 模糊查询 LIKEnotLike 模糊查询 NOT LIKEin IN 查询notIn NOT IN 查询isNull NULL 值查询isNotNull IS NOT NULLgroupBy 分组 GROUP BYhaving HAVING 关键词orderBy 排序 ORDER BYorderAsc ASC 排序 ORDER BYorderDesc DESC 排序 ORDER BYexists EXISTS 条件语句notExists NOT EXISTS 条件语句between BETWEEN 条件语句notBetween NOT BETWEEN 条件语句addFilter 自由拼接 SQLlast 拼接在最后,例如:last("LIMIT 1")