5 Star 29 Fork 5

左羽空间 / easy-mybatis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

easy-mybatis是一个对Mybatis的增强框架(插件)。在Spring集成Mybatis的基础上,将项目开发中对数据库的常用操作统一化。使用本框架可以很便捷的对数据库进行操作,提高开发效率,减少机械行为。

这个框架的初衷是,减少Java程序员千篇一律的数据库操作:主题初衷与诞生

特性

  • 更便捷

摒弃传统mybatismodelxmldao数据库操作模式,避繁就简,快速开发。

  • 更高效

采用预编译SQL,拒绝运行期间反射生成SQL,性能更高效。

  • 无侵入

只是对Mybatis-Spring的增强插件,对已有工程不做任何修改,仍可使用原生框架的功能,仅仅是简化了开发阶段对数据库的操作。

  • 统一操作接口

对数据库的所有操作共用一个接口,降低使用门槛,轻松操作数据库。

  • 统一操作对象

使用JsonObject为数据对象,提供一系列操作方法,方便从持久化对象组装为视图对象。

  • 易上手

整个框架只提供了一个接口、一个注解、两个对象,仅仅一行配置便可完成对数据库进行常用操作。

  • ...

安利

  • mybatis-spring-boot环境下,使用该框架(插件),可以减少传统Mybatis使用中对modelxmldao的机械式开发。

  • 所有的数据库操作均使用MapperRepository接口,通过注解@Magic("xxx")标记接口的数据表归属,即可直接使用。

  • 该框架(插件)不妨碍同时使用传统Mybatismodelxmldao的数据库开发方式。

别犹豫了,一起上手吧——快速上手


本框架(插件)基于mybatis-spring-boot环境。

安装

  • 安装mybatis-spring-boot环境

mybatis-spring-boot的Maven依赖:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>${spring-boot.version}</version>
        <relativePath/>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>${mybatis-spring-boot.version}</version>
        </dependency>
    </dependencies>

mybatis-spring-boot的Gradle依赖:

    plugins {
    id 'org.springframework.boot' version '${springBootVersion}'
    id 'io.spring.dependency-management' version '${springManagementVersion}'
    id 'java'
    }

    dependencies {
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringVersion}'
    }
  • 安装本框架(插件)

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'

配置

  1. 配置spring-boot-jdbc数据库

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

关于springBoot的配置,这里不多赘述,更多移步springBoot官网

  1. 配置easy-mybatis支持的表名(例子)

easy-mybatis:
  table-names: teacher, student

这里的table-names配置,表示需要easy-mybatis框架支持的数据表名,多个表名使用逗号隔开。

即可使用easy-mybatis框架操作teacherstudent两个数据表,如果需要支持其他数据表,需要在此配置

  1. 操作数据库(例子)

@SpringBootTest
class DemoApplicationTests {

    // 表示该接口用来操作名称为'teacher'的数据表
    @Magic("teacher")
    private MapperRepository teacherRepository;

    // 表示该接口用来操作名称为'student'的数据表
    @Magic("student")
    private MapperRepository studentRepository;


    // 查询teacher表下所有数据
    @Test
    void teacherTest() {
        teachertRepository.selectList().forEach(System.out::println);
    }

    // 查询student表下符合特定条件的数据
    @Test
    void studentTest() {
        studentRepository.selectListByExample(
          new JsonObject().put("birthday", "2009/12/12 12:12:12")
          ).forEach(System.out::println);
    }

}

使用MapperRepository接口对数据库进行操作,需要使用@Magic("表名称")标记该接口的数据表归属。

在本例中,@Magic("teacher")表示该MapperRepository"teacher"数据表的操作接口,可以通过teacherRepository调用一系列方法完成对"teacher"数据表的操作。

关于本框架(插件)的更多信息,请前往官方网站

MIT License Copyright (c) 2021 zuoyuip@foxmail.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个把Mybatis操作简化至极致的框架 展开 收起
Java
MIT
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/zuoyuip/easy-mybatis.git
git@gitee.com:zuoyuip/easy-mybatis.git
zuoyuip
easy-mybatis
easy-mybatis
main

搜索帮助