成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

JavaFluentMybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

這篇文章主要介紹了Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成文章都會(huì)有所收獲,下面我們一起來看看吧。

站在用戶的角度思考問題,與客戶深入溝通,找到信陽網(wǎng)站設(shè)計(jì)與信陽網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:做網(wǎng)站、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、國際域名空間、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋信陽地區(qū)。

特性

看一下官方給出的特性圖

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

給出對(duì)幾個(gè)特性乍一看還是很全面的,其中比較吸引我的是兩點(diǎn)。

1、從圖中給出的語法,和sql十分相近,不仔細(xì)看還以為是直接sql語句扔了上來??瓷先ゾ捅容^實(shí)用。

2、No xml&mapper,雖然mybatis-plus已經(jīng)做到實(shí)用 IService接口實(shí)現(xiàn)大部分的sql操作

項(xiàng)目搭建

springboot搭建一項(xiàng)目的過程就不過多贅述了,這里說下我實(shí)用的springboot版本

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

代碼結(jié)構(gòu)如下:

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

maven依賴引入-fluent-mybatis
<properties>
    <fluent-mybatis.version>1.8.7</fluent-mybatis.version>
</properties>
<dependencies>
    <!-- 引入fluent-mybatis 運(yùn)行依賴包, scope為compile -->
    <dependency>
        <groupId>com.github.atool</groupId>
        <artifactId>fluent-mybatis</artifactId>
        <version>${fluent-mybatis.version}</version>
    </dependency>
    <!-- 引入fluent-mybatis-processor, scope設(shè)置為provider 編譯需要,運(yùn)行時(shí)不需要 -->
    <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 運(yùn)行依賴包, scope為compile -->
        <dependency>
            <groupId>com.github.atool</groupId>
            <artifactId>fluent-mybatis</artifactId>
            <version>${fluent-mybatis.version}</version>
        </dependency>
        <!-- 引入fluent-mybatis-processor, scope設(shè)置為provider 編譯需要,運(yùn)行時(shí)不需要 -->
        <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>
表構(gòu)建

在數(shù)據(jù)庫創(chuàng)建一張測(cè)試表,表比較簡單,先試試看。sql如下:

CREATE TABLE `test_fluent_mybatis` (
  `id` int NOT NULL AUTO_INCREMENT COMMENT '自增主鍵',
  `name` varchar(255) DEFAULT NULL COMMENT '姓名',
  `age` int DEFAULT NULL COMMENT '年齡',
  `create_time` datetime DEFAULT NULL COMMENT '創(chuàng)建時(shí)間',
  `del_flag` int DEFAULT NULL COMMENT '是否刪除',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
代碼生成工具類

注意:放到測(cè)試代碼包中。結(jié)構(gòu)如下圖:

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

代碼生成工具類代碼,先按照官方給的簡單樣例來,如下:

package com.hy.fmp;
 
import cn.org.atool.generator.FileGenerator;
import cn.org.atool.generator.annotation.Table;
import cn.org.atool.generator.annotation.Tables;
import org.junit.jupiter.api.Test;
 
public class EntityGeneratorDemo {
  // 數(shù)據(jù)源 url
  static final String url =
      "jdbc:mysql://192.168.0.16:3306/test?useUnicode=true&characterEncoding=utf8";
  // 數(shù)據(jù)庫用戶名
  static final String username = "root";
  // 數(shù)據(jù)庫密碼
  static final String password = "123456";
 
  @Test
  public void generate() throws Exception {
    // 引用配置類,build方法允許有多個(gè)配置類
    FileGenerator.build(Empty.class);
  }
 
  @Tables(
      // 設(shè)置數(shù)據(jù)庫連接信息
      url = url,
      username = username,
      password = password,
      // 設(shè)置entity類生成src目錄, 相對(duì)于 user.dir
      srcDir = "src/main/java",
      // 設(shè)置entity類的package值
      basePack = "com.hy.fmp.fluent",
      // 設(shè)置dao接口和實(shí)現(xiàn)的src目錄, 相對(duì)于 user.dir
      daoDir = "src/main/java",
      // 設(shè)置哪些表要生成Entity文件
      tables = {@Table(value = {"test_fluent_mybatis"})})
  static class Empty { // 類名隨便取, 只是配置定義的一個(gè)載體
  }
}

執(zhí)行代碼生成工具,看看都生成了些什么。

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

可以看到生成的包如下。

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

解決類找不到問題

這里有個(gè)坑,看下面的截圖

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

其實(shí)官方給了解決方法,只是沒有對(duì)此說明。

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

簡而言之就是你需要使用maven編譯一下,所以我們compile一下。

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

編譯結(jié)束后我們可以在target中,找到報(bào)錯(cuò)包位置中的編譯文件。

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

之前報(bào)錯(cuò)的類已經(jīng)不再報(bào)錯(cuò)了。完美。

Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成

關(guān)于“Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“Java Fluent Mybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

本文標(biāo)題:JavaFluentMybatis怎么構(gòu)建項(xiàng)目與實(shí)現(xiàn)代碼生成
鏈接地址:http://jinyejixie.com/article38/psijsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、用戶體驗(yàn)、商城網(wǎng)站網(wǎng)站設(shè)計(jì)公司服務(wù)器托管、網(wǎng)站維護(hù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)
金沙县| 昂仁县| 东台市| 宁南县| 株洲市| 太原市| 乡宁县| 株洲市| 嫩江县| 鄂温| 南宁市| 洪湖市| 昔阳县| 清镇市| 开化县| 元阳县| 二连浩特市| 固镇县| 民乐县| 平遥县| 东港市| 隆尧县| 开原市| 伊金霍洛旗| 伊通| 上高县| 巩义市| 田东县| 浠水县| 安顺市| 宜州市| 楚雄市| 太康县| 渑池县| 文水县| 肃宁县| 北流市| 亳州市| 扎鲁特旗| 盐津县| 凉城县|