FluentMybatis 项目构建、代码生成(一) | FluentMybatis实践(2)

简介: FluentMybatis 项目构建、代码生成(一) | FluentMybatis实践

简述

偶然看到一篇关于阿里新orm框架的文章,好奇的点了进去。开发后端多年,看到这个还是有点兴奋的。常用mysql的orm框架mybatis、jpa,到后来的优化框架mybatis-plus都是用过,他们或多或少都有优缺点吧。程序员本就是日常革新技术的职业,所以了解更多的框架绝对不会有错误。所以我尝试着把自己学习该框架的过程,记录下来,尽可能去掉一些项目工程中用不到的功能,展示一些实用有帮助的代码。



特性

首先分享一下码云上的项目链接:码云地址

看一下官方给出的特性图


image.png

给出对几个特性乍一看还是很全面的,其中比较吸引我的是两点。


1、从图中给出的语法,和sql十分相近,不仔细看还以为是直接sql语句扔了上来。看上去就比较实用。


2、No xml&mapper,虽然mybatis-plus已经做到实用 IService接口实现大部分的sql操作


项目搭建

springboot搭建一项目的过程就不过多赘述了,这里说下我实用的springboot版本


 

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

代码结构如下:


image.png

maven依赖引入-fluent-mybatis


<properties>
    <fluent-mybatis.version>1.8.7</fluent-mybatis.version>
</properties>
<dependencies>
    <!-- 引入fluent-mybatis 运行依赖包, scope为compile -->
    <dependency>
        <groupId>com.github.atool</groupId>
        <artifactId>fluent-mybatis</artifactId>
        <version>${fluent-mybatis.version}</version>
    </dependency>
    <!-- 引入fluent-mybatis-processor, scope设置为provider 编译需要,运行时不需要 -->
    <dependency>
        <groupId>com.github.atool</groupId>
        <artifactId>fluent-mybatis-processor</artifactId>
        <scope>provided</scope>
        <version>${fluent-mybatis.version}</version>
    </dependency>
</dependencies>

完整maven依赖如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.hy</groupId>
    <artifactId>fluent-mybatis-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>fluent-mybatis-project</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <fluent-mybatis.version>1.8.7</fluent-mybatis.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org</groupId>
            <artifactId>jaudiotagger</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>30.1.1-jre</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.5.2</version>
        </dependency>
        <!-- 引入fluent-mybatis 运行依赖包, scope为compile -->
        <dependency>
            <groupId>com.github.atool</groupId>
            <artifactId>fluent-mybatis</artifactId>
            <version>${fluent-mybatis.version}</version>
        </dependency>
        <!-- 引入fluent-mybatis-processor, scope设置为provider 编译需要,运行时不需要 -->
        <dependency>
            <groupId>com.github.atool</groupId>
            <artifactId>fluent-mybatis-processor</artifactId>
            <scope>provided</scope>
            <version>${fluent-mybatis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
相关文章
|
7月前
|
存储 人工智能 自然语言处理
知识库管理:全流程智能化中枢,驱动企业信息资产高效流转
智能系统的知识库管理技术可以深度融合AI技术与精细化流程控制,提供从内容创建到版本追溯的全生命周期管理。支持多模态数据统一存储(文本、语音、图像等),实现自动化审核、智能分类与语义检索,确保企业知识资产的安全存储与高效利用,助力业务持续优化。核心功能包括多角色协作编辑、动态标签管理、历史版本追溯及毫秒级语义检索,大幅提升信息管理效率与准确性。
276 9
|
SQL 存储 JSON
更快更强,SLS 推出高性能 SPL 日志查询模式
从海量的日志数据中,按照各种灵活的条件进行即时查询搜索,是可观测场景下的基本需求。本文介绍了 SLS 新推出的高性能 SPL 日志查询模式,支持 Unix 风格级联管道式语法,以及各种丰富的 SQL 处理函数。同时通过计算下推、向量化计算等优化,使得 SPL 查询可以在数秒内处理亿级数据,并支持 SPL 过滤结果分布图、随机翻页等特性。
13120 214
|
SQL Java 数据库连接
解决mybatis-plus 拦截器不生效--分页插件不生效
本文介绍了在使用 Mybatis-Plus 进行分页查询时遇到的问题及解决方法。依赖包包括 `mybatis-plus-boot-starter`、`mybatis-plus-extension` 等,并给出了正确的分页配置和代码示例。当分页功能失效时,需将 Mybatis-Plus 版本改为 3.5.5 并正确配置拦截器。
3879 6
解决mybatis-plus 拦截器不生效--分页插件不生效
|
前端开发 小程序 Java
【规范】SpringBoot接口返回结果及异常统一处理,这样封装才优雅
本文详细介绍了如何在SpringBoot项目中统一处理接口返回结果及全局异常。首先,通过封装`ResponseResult`类,实现了接口返回结果的规范化,包括状态码、状态信息、返回信息和数据等字段,提供了多种成功和失败的返回方法。其次,利用`@RestControllerAdvice`和`@ExceptionHandler`注解配置全局异常处理,捕获并友好地处理各种异常信息。
5709 0
【规范】SpringBoot接口返回结果及异常统一处理,这样封装才优雅
|
传感器 人工智能 物联网
【C 言专栏】C 语言与硬件交互的方法
【5月更文挑战第4天】C 语言在硬件交互中扮演关键角色,主要通过直接访问硬件寄存器、中断处理、I/O 端口操作、内存映射I/O和设备驱动程序开发。挑战包括硬件多样性、实时性要求和错误处理。随着物联网和人工智能发展,C语言与硬件交互的需求增加,未来将面临更多新硬件和技术的挑战。本文旨在帮助读者理解和掌握这一领域的知识,以实现更高效的硬件互动。
397 1
【C 言专栏】C 语言与硬件交互的方法
|
XML Java 数据格式
java使用Document类解析xml并创建子标签节点
java使用Document类解析xml并创建子标签节点
|
数据采集 监控 Java
Spring Boot拦截器:精细化控制请求与响应
本篇详细介绍了在Spring Boot中使用拦截器的方法。拦截器是一种强大的机制,可用于在请求处理前后进行操作,如鉴权、日志记录等。文章涵盖了创建拦截器类、注册拦截器以及实际应用案例。通过具体的代码示例,读者可以了解如何在项目中配置和使用拦截器,以实现各种功能需求。拦截器为Spring Boot应用增加了更多的灵活性和可扩展性,能够提升应用的安全性和可维护性。
3217 0
Spring Boot拦截器:精细化控制请求与响应
|
负载均衡 网络协议 应用服务中间件
使用阿里云NLB获取客户端原地址
本文为您介绍NLB如何获取客户端真实IP,及通过Proxy Protocol获取客户端真实IP的场景和配置教程。
869 1
|
SQL XML IDE
Let's Fluent:更顺滑的MyBatis
只需瞅一眼Google Trends上全球Java界最热门的两款SQL映射框架近一年的对比数字,就不难了解其实力分布:在此领域,MyBatis早已占领东亚地区开发者市场,并以绝对优势稳居中国最抢手Java数据库访问框架之首。
Let's Fluent:更顺滑的MyBatis
|
SQL XML IDE
Fluent mybatis
众多框架都是从无到有,从有到简的一个过程,核心理念都是为简化开发为生。
720 0
Fluent mybatis