1. 程式人生 > 其它 >mybatis plus、條件、構造器、常用詞解釋

mybatis plus、條件、構造器、常用詞解釋

技術標籤:mybatismysqlsqlmybatisjava資料庫

實體包裝器,用於處理 sql 拼接,排序,實體引數查詢

進行詳細拼接解析:

  • 拼接 sql 方式 一
@Test
public 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 方法如何使用 Wrapper

  • mapper 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 模糊查詢 LIKE
notLike 模糊查詢 NOT LIKE
in IN 查詢
notIn NOT IN 查詢
isNull NULL 值查詢
isNotNull IS NOT NULL
groupBy 分組 GROUP BY
having HAVING 關鍵詞
orderBy 排序 ORDER BY
orderAsc ASC 排序 ORDER BY
orderDesc DESC 排序 ORDER BY
exists EXISTS 條件語句
notExists NOT EXISTS 條件語句
between BETWEEN 條件語句
notBetween NOT BETWEEN 條件語句
addFilter 自由拼接 SQL
last 拼接在最後,例如:last("LIMIT 1")