日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tkmybatis通用mapper实现在使用Example进行查询的几种方式

發(fā)布時間:2024/1/1 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tkmybatis通用mapper实现在使用Example进行查询的几种方式 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

如下列舉四種方式,但是不止四種哦。

其中weekend方式需要升級jdk到1.8及以上。

廢話不代碼!

首先定義數(shù)據(jù)庫表映射類:

public class MybatisDemo {private Long id;private Long count;private String name;public Long getId() {return id;}public Long getCount() {return count;}public String getName() {return name;}// setter…… }

此處省略了數(shù)據(jù)庫表映射和set方法。

接下來就是實現(xiàn)example查詢的幾種方式,核心代碼如下:

方式一:普通Example方式(從and方法開始可以實現(xiàn)動態(tài)sql拼接)

????Example example = new Example(CandidateBrandEntity.class);example//.selectProperties("cabId","cabName").and().andEqualTo("cabDeleted",0).andLike("cabName","%d%");// 排序example.orderBy("cabCreatedTime")/*.desc()*/.orderBy("cabId").desc();// 獲得結果List<CandidateBrandEntity> brands = brandEntityMapper.selectByExample(example);

方式二:Criteria方式(可使用criteria完成動態(tài)sql拼接)

Example example = new Example(MybatisDemo.class); Example.Criteria criteria = example.createCriteria(); criteria.andEqualTo("count", 0).andLike("name", "%d%"); example.orderBy("count")//.desc().orderBy("name").desc(); List<MybatisDemo> demos = mybatisDemoMapper.selectByExample(example);

方式三:Example.builder 方式(其中where從句中內(nèi)容可以拿出來進行動態(tài)sql拼接)

Example example = Example.builder(MybatisDemo.class).select("cabId","cabName").where(Sqls.custom().andEqualTo("count", 0).andLike("name", "%d%")).orderByDesc("count","name").build(); List<MybatisDemo> demos = mybatisDemoMapper.selectByExample(example);

方式四:Example.builder + Weekend方式,優(yōu)勢:不用輸入屬性名,避免數(shù)據(jù)庫有變動或輸入錯誤就會出錯

//獲得seekendsql WeekendSqls<MybatisDemo> sqls = WeekendSqls.<MybatisDemo>custom();//可進行動態(tài)sql拼接 sqls = sqls.andEqualTo(MybatisDemo::getCount,0).andLike(MybatisDemo::getName,"%d%");//獲得結果 List<MybatisDemo> demos = mybatisDemoMapper.selectByExample(Example.builder(MybatisDemo.class).where(sqls).orderByDesc("count","name").build());

?

?

參考內(nèi)容:https://github.com/abel533/Mapper/wiki/6.example

總結

以上是生活随笔為你收集整理的tkmybatis通用mapper实现在使用Example进行查询的几种方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。