<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          easy-mybatisMybatis 的增強框架

          聯(lián)合創(chuàng)作 · 2023-10-01 07:24

          easy-mybatis是一個對Mybatis的增強框架(插件)。在Spring集成Mybatis的基礎(chǔ)上,將項目開發(fā)中對數(shù)據(jù)庫的常用操作統(tǒng)一化。使用本框架可以很便捷的對數(shù)據(jù)庫進(jìn)行操作,提高開發(fā)效率,減少機械行為。

          Maven依賴引入

          
          <!-- https://mvnrepository.com/artifact/top.zuoyu.mybatis/easy-mybatis-spring-boot-starter -->
          <dependency>
              <groupId>top.zuoyu.mybatis</groupId>
              <artifactId>easy-mybatis-spring-boot-starter</artifactId>
              <version>1.0.0</version>
          </dependency>
          
          

          Gradle依賴引入

          
          // https://mvnrepository.com/artifact/top.zuoyu.mybatis/easy-mybatis-spring-boot-starter
          implementation 'top.zuoyu.mybatis:easy-mybatis-spring-boot-starter:1.0.0'
          
          

          框架特性

          • 更便捷

          摒棄傳統(tǒng)mybatismodelxmldao數(shù)據(jù)庫操作模式,避繁就簡,快速開發(fā)。

          • 更高效

          采用預(yù)編譯SQL,拒絕運行期間反射生成SQL,性能更高效。

          • 無侵入

          只是對Mybatis-Spring的增強插件,對已有工程不做任何修改,仍可使用原生框架的功能,僅僅是簡化了開發(fā)階段對數(shù)據(jù)庫的操作。

          • 統(tǒng)一操作接口

          對數(shù)據(jù)庫的所有操作共用一個接口,降低使用門檻,輕松操作數(shù)據(jù)庫。

          • 統(tǒng)一操作對象

          使用JsonObject為數(shù)據(jù)對象,提供一系列操作方法,方便從持久化對象組裝為視圖對象。

          • 易上手

          整個框架只提供了一個接口、一個注解、兩個對象,僅僅一行配置便可完成對數(shù)據(jù)庫進(jìn)行常用操作。

          • ...

          安利

          • mybatis-spring-boot環(huán)境下,使用該框架(插件),可以減少傳統(tǒng)Mybatis使用中對modelxmldao的機械式開發(fā)。

          • 所有的數(shù)據(jù)庫操作均使用MapperRepository接口,通過注解@Magic("xxx")標(biāo)記接口的數(shù)據(jù)表歸屬,即可直接使用。

          • 該框架(插件)不妨礙同時使用傳統(tǒng)Mybatismodelxmldao的數(shù)據(jù)庫開發(fā)方式。

          快速上手

          這里以MySQL數(shù)據(jù)庫為例,Oracle數(shù)據(jù)庫配置請參考配置說明

          1. 配置spring-boot-jdbc數(shù)據(jù)庫
          
          spring:
            datasource:
              type: com.zaxxer.hikari.HikariDataSource
              driver-class-name: com.mysql.cj.jdbc.Driver
              url: jdbc:mysql://172.0.0.1:3306/xxxx
              username: xxxx
              password: xxxx
          
          

          關(guān)于springBoot的配置,這里不多贅述,更多移步springBoot官網(wǎng)

          1. 配置easy-mybatis支持的表名(例子)
          
          easy-mybatis:
            table-names: teacher, student
          
          

          這里的table-names配置,表示需要easy-mybatis框架支持的數(shù)據(jù)表名,多個表名使用逗號隔開。

          即可使用easy-mybatis框架操作teacherstudent兩個數(shù)據(jù)表,如果需要支持其他數(shù)據(jù)表,需要在此配置

          操作數(shù)據(jù)庫(例子)

          
          @SpringBootTest
          class DemoApplicationTests {
          
              // 表示該接口用來操作名稱為'teacher'的數(shù)據(jù)表
              @Magic("teacher")
              private MapperRepository teacherRepository;
          
              // 表示該接口用來操作名稱為'student'的數(shù)據(jù)表
              @Magic("student")
              private MapperRepository studentRepository;
          
          
              // 查詢teacher表下所有數(shù)據(jù)
              @Test
              void teacherTest() {
                  teachertRepository.selectList().forEach(System.out::println);
              }
          
              // 查詢student表下符合特定條件的數(shù)據(jù)
              @Test
              void studentTest() {
                  studentRepository.selectListByExample(
                    new JsonObject().put("birthday", "2009/12/12 12:12:12")
                    ).forEach(System.out::println);
              }
          
          }
          
          

          使用MapperRepository接口對數(shù)據(jù)庫進(jìn)行操作,需要使用@Magic("表名稱")標(biāo)記該接口的數(shù)據(jù)表歸屬。

          在本例中,@Magic("teacher")表示該MapperRepository"teacher"數(shù)據(jù)表的操作接口,可以通過teacherRepository調(diào)用一系列方法完成對"teacher"數(shù)據(jù)表的操作。

           

          瀏覽 40
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  少妇大战黑人无套A片 | 男人的天堂在线视频 | 日本A在线看 | 欧美性操 | 国产免费黄色网址 |