最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java mybatis-plus詳解

 更新時間:2021年09月22日 08:47:28   作者:--流星。  
MyBatis-Plus是一個MyBatis的增強工具,在MyBatis的基礎上只做增強不做修改,為簡化開發(fā)、提高效率而生,本文給大家詳細講解一下MyBatis-Plus,需要的朋友參考下吧

1、簡介

MyBatis-Plus 是一個 Mybatis 增強版工具,在 MyBatis 上擴充了其他功能沒有改變其基本功能,為了簡化開發(fā)提交效率而存在。

2、適用情況

1、對于只進行單表操作來說,mybatis-plus代碼量比mybatis的代碼量少很多,極大的提高了開發(fā)效率
2、對于多表操作來說,更推薦mybatis,因為mybatis-plus的方法比較難以理解,用起來不太方便,不如自己寫sql語句的邏輯那么清晰明了

3、mybatis-plus前期準備(工程將以 H2 作為默認數(shù)據(jù)庫進行演示)

1、使用 Spring Initializer快速初始化一個 Spring Boot 工程

2、導入mybatis-plus依賴

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>spring-latest-version</version>
    <relativePath/>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>Latest Version</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
</dependencies>

3、yml文件中添加相關配置

# DataSource Config
spring:
  datasource:
    driver-class-name: org.h2.Driver
    schema: classpath:db/schema-h2.sql
    data: classpath:db/data-h2.sql
    url: jdbc:h2:mem:test
    username: root
    password: test

4、在 Spring Boot 啟動類中添加 @MapperScan 注解,掃描 Mapper 文件夾

@MapperScan("com.baomidou.mybatisplus.samples.quickstart.mapper")

5、編寫實體類和Mapper類

//entity
@Data
public class User {
    private Long id;
    private String name;
    private Integer age;
    private String email;
}

//Mapper
public interface UserMapper extends BaseMapper<User> {
}

6、service繼承IService

public interface UserService extends IService<User> 

7、serviceImpl繼承ServiceImpl

public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService

4、mybatis-plus的sql操作(Service層)

1、Save:插入

// 插入一條記錄(選擇字段,策略插入)
boolean save(T entity);
// 插入(批量)
boolean saveBatch(Collection<T> entityList);
// 插入(批量)
boolean saveBatch(Collection<T> entityList, int batchSize);

在這里插入圖片描述

2、SaveOrUpdate:修改插入

// TableId 注解存在更新記錄,否插入一條記錄
boolean saveOrUpdate(T entity);
// 根據(jù)updateWrapper嘗試更新,否繼續(xù)執(zhí)行saveOrUpdate(T)方法
boolean saveOrUpdate(T entity, Wrapper<T> updateWrapper);
// 批量修改插入
boolean saveOrUpdateBatch(Collection<T> entityList);
// 批量修改插入
boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);

在這里插入圖片描述

3、Remove:刪除

// 根據(jù) entity 條件,刪除記錄
boolean remove(Wrapper<T> queryWrapper);
// 根據(jù) ID 刪除
boolean removeById(Serializable id);
// 根據(jù) columnMap 條件,刪除記錄
boolean removeByMap(Map<String, Object> columnMap);
// 刪除(根據(jù)ID 批量刪除)
boolean removeByIds(Collection<? extends Serializable> idList);

4、Update:更新

// 根據(jù) UpdateWrapper 條件,更新記錄 需要設置sqlset
boolean update(Wrapper<T> updateWrapper);
// 根據(jù) whereWrapper 條件,更新記錄
boolean update(T updateEntity, Wrapper<T> whereWrapper);
// 根據(jù) ID 選擇修改
boolean updateById(T entity);
// 根據(jù)ID 批量更新
boolean updateBatchById(Collection<T> entityList);
// 根據(jù)ID 批量更新
boolean updateBatchById(Collection<T> entityList, int batchSize);

在這里插入圖片描述

5、Get:單體查詢

// 根據(jù) ID 查詢
T getById(Serializable id);
// 根據(jù) Wrapper,查詢一條記錄。結果集,如果是多個會拋出異常,隨機取一條加上限制條件 wrapper.last("LIMIT 1")
T getOne(Wrapper<T> queryWrapper);
// 根據(jù) Wrapper,查詢一條記錄
T getOne(Wrapper<T> queryWrapper, boolean throwEx);
// 根據(jù) Wrapper,查詢一條記錄
Map<String, Object> getMap(Wrapper<T> queryWrapper);
// 根據(jù) Wrapper,查詢一條記錄
<V> V getObj(Wrapper<T> queryWrapper, Function<? super Object, V> mapper)

在這里插入圖片描述

6、List:多條查詢

// 查詢所有
List<T> list();
// 查詢列表
List<T> list(Wrapper<T> queryWrapper);
// 查詢(根據(jù)ID 批量查詢)
Collection<T> listByIds(Collection<? extends Serializable> idList);
// 查詢(根據(jù) columnMap 條件)
Collection<T> listByMap(Map<String, Object> columnMap);
// 查詢所有列表
List<Map<String, Object>> listMaps();
// 查詢列表
List<Map<String, Object>> listMaps(Wrapper<T> queryWrapper);
// 查詢全部記錄
List<Object> listObjs();
// 查詢全部記錄
<V> List<V> listObjs(Function<? super Object, V> mapper);
// 根據(jù) Wrapper 條件,查詢全部記錄
List<Object> listObjs(Wrapper<T> queryWrapper);
// 根據(jù) Wrapper 條件,查詢全部記錄
<V> List<V> listObjs(Wrapper<T> queryWrapper, Function<? super Object, V> mapper);

在這里插入圖片描述

7、Page:分頁查詢(需要導入相關的配置或依賴)

// 無條件分頁查詢
IPage<T> page(IPage<T> page);
// 條件分頁查詢
IPage<T> page(IPage<T> page, Wrapper<T> queryWrapper);
// 無條件分頁查詢
IPage<Map<String, Object>> pageMaps(IPage<T> page);
// 條件分頁查詢
IPage<Map<String, Object>> pageMaps(IPage<T> page, Wrapper<T> queryWrapper);

在這里插入圖片描述

8、Count:記錄數(shù)據(jù)個數(shù)

// 查詢總記錄數(shù)
int count();
// 根據(jù) Wrapper 條件,查詢總記錄數(shù)
int count(Wrapper<T> queryWrapper);

5、詳細資料

由于篇幅有限,先寫到這里
具體內容請看
1、mybatis-plus官網(wǎng):https://mp.baomidou.com/
2、MyBatis-Plus 通用IService使用詳解

總結

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關注腳本之家的更多內容!

相關文章

  • java獲取http請求的Header和Body的簡單方法

    java獲取http請求的Header和Body的簡單方法

    下面小編就為大家?guī)硪黄猨ava獲取http請求的Header和Body的簡單方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-11-11
  • Springboot 使用內置tomcat禁止不安全HTTP的方法

    Springboot 使用內置tomcat禁止不安全HTTP的方法

    這篇文章主要介紹了Springboot 使用內置tomcat禁止不安全HTTP的方法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • Spring請求參數(shù)校驗功能實例演示

    Spring請求參數(shù)校驗功能實例演示

    這篇文章主要介紹了Spring請求參數(shù)校驗功能實例演示,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧
    2018-05-05
  • maven導入本地jar包的三種方式

    maven導入本地jar包的三種方式

    本文主要介紹了maven導入本地jar包的三種方式,?文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2024-04-04
  • java實現(xiàn)雙色球抽獎算法

    java實現(xiàn)雙色球抽獎算法

    這篇文章主要為大家詳細介紹了java實現(xiàn)雙色球抽獎算法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-05-05
  • jpa?EntityManager?復雜查詢實例

    jpa?EntityManager?復雜查詢實例

    這篇文章主要介紹了jpa?EntityManager?復雜查詢實例,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • SpringMvc入門指南(必看)

    SpringMvc入門指南(必看)

    下面小編就為大家?guī)硪黄猄pringMvc入門指南(必看)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-06-06
  • Java深入分析與解決Top-K問題

    Java深入分析與解決Top-K問題

    TopK問題即在N個數(shù)中找出最大的前K個,這篇文章將詳細講解三種方法解決TopK問題,文中代碼具有一定參考價值,快跟隨小編一起學習一下吧
    2022-04-04
  • 詳解Java中的封裝、繼承、多態(tài)

    詳解Java中的封裝、繼承、多態(tài)

    本文主要介紹了Java中的封裝、繼承、多態(tài)的相關知識,具有一定的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • nacos客戶端一致性hash負載需求實現(xiàn)

    nacos客戶端一致性hash負載需求實現(xiàn)

    這篇文章主要介紹了nacos客戶端一致性hash負載的需求實現(xiàn)過程及步驟詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步
    2022-02-02

最新評論

凯里市| 黄石市| 泗阳县| 长寿区| 怀安县| 锡林郭勒盟| 长葛市| 鄂州市| 牟定县| 镇赉县| 昌吉市| 辽宁省| 洛扎县| 绥化市| 石屏县| 汤原县| 龙门县| 玉山县| 河间市| 绍兴县| 海口市| 东阳市| 余干县| 高要市| 甘肃省| 宁南县| 济阳县| 莆田市| 旌德县| 东阳市| 禹城市| 隆尧县| 高台县| 柘荣县| 洛宁县| 莱州市| 建平县| 长治县| 中牟县| 林州市| 小金县|