Mybatisplus和JdbcTemplate的簡單使用


Mybatisplus

簡介

MyBatis-Plus (opens new window)(簡稱 MP)是一個 MyBatis (opens new window)的增強工具,在 MyBatis 的基礎上只做增強不做改變,為簡化開發、提高效率而生。
官方網址:https://mp.baomidou.com/guide/

特點

提供了多數據源、sql編寫增強、注解、分頁,相對於mybatis來說,更加好用。

依賴

根據官網進行相關配置即可,略。

Gitee案例地址

https://gitee.com/zhuayng/foundation-study/tree/develop/JDBCFramework/MybatisPlus

JdbcTemplate

簡介

對jdbc的簡單封裝,簡化了數據庫連接管理,以及對字段查詢結果的映射關系。
官方網址:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html

特點

小型的項目,對sql要求不高,或者底層進行jdbc封裝,用於更復雜的項目,優先考慮JdbcTemplate。

常用方法

public T queryForObject(String sql, RowMapper rowMapper, @Nullable Object... args) : 根據sql和參數查詢一個實體對象;
public T queryForObject(String sql, Class requiredType, @Nullable Object... args) : 根據sql和參數查詢一列且一個值;
public List query(String sql, RowMapper rowMapper) throws DataAccessException : 根據sql查詢多個實體對象;
public int update(String sql, @Nullable Object... args):根據sql和參數對數據庫進行增刪改操作。

依賴

    <!--springBoot集成jdbc-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
        </dependency>	

Gitee案例地址

https://gitee.com/zhuayng/foundation-study/tree/develop/JDBCFramework/JdbcTemplate


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM