欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringBoot使用Mybatis-Generator配置過(guò)程詳解

 更新時(shí)間:2020年02月26日 13:35:47   投稿:yaominghui  
這篇文章主要介紹了SpringBoot使用Mybatis-Generator配置過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

:> 使用Spring initialier 需要配置文件

POM文件


復(fù)制代碼 代碼如下:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <executions> <execution> <id>mybatis-generator</id> <phase>deploy</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <!-- Mybatis-Generator 工具配置文件的位置 --> <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.19</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version>a </dependency> </dependencies> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <classifier>exec</classifier> </configuration> </plugin> </plugins> </build>
1: application配置文件

復(fù)制代碼 代碼如下:
## mapper xml 文件地址mybatis.mapper-locations=classpath*:mapper/*Mapper.xml##數(shù)據(jù)庫(kù)urlspring.datasource.url=jdbc:mysql://localhost/test2?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT##數(shù)據(jù)庫(kù)用戶名spring.datasource.username=root##數(shù)據(jù)庫(kù)密碼spring.datasource.password=root##數(shù)據(jù)庫(kù)驅(qū)動(dòng)spring.datasource.driver-class-name=com.mysql.jdbc.Driver#Mybatis Generator configuration#dao類和實(shí)體類的位置mybatis.project =src/main/java#mapper文件的位置mybatis.resources=src/main/resources
配置 Mybatis-Generator
復(fù)制代碼 代碼如下:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"><!-- 配置生成器 --><generatorConfiguration> <!--執(zhí)行g(shù)enerator插件生成文件的命令: call mvn mybatis-generator:generate -e --> <!-- 引入配置文件 --> <properties resource="application.properties"/> <!--classPathEntry:數(shù)據(jù)庫(kù)的JDBC驅(qū)動(dòng),換成你自己的驅(qū)動(dòng)位置 可選 --> <!--<classPathEntry location="D:\generator_mybatis\mysql-connector-java-5.1.24-bin.jar" /> --> <!-- 一個(gè)數(shù)據(jù)庫(kù)一個(gè)context --> <!--defaultModelType="flat" 大數(shù)據(jù)字段,不分表 --> <context targetRuntime="MyBatis3Simple" defaultModelType="flat"> <!-- 自動(dòng)識(shí)別數(shù)據(jù)庫(kù)關(guān)鍵字,默認(rèn)false,如果設(shè)置為true,根據(jù)SqlReservedWords中定義的關(guān)鍵字列表; 一般保留默認(rèn)值,遇到數(shù)據(jù)庫(kù)關(guān)鍵字(Java關(guān)鍵字),使用columnOverride覆蓋 --> <property name="autoDelimitKeywords" value="true" /> <!-- 生成的Java文件的編碼 --> <property name="javaFileEncoding" value="utf-8" /> <!-- beginningDelimiter和endingDelimiter:指明數(shù)據(jù)庫(kù)的用于標(biāo)記數(shù)據(jù)庫(kù)對(duì)象名的符號(hào),比如ORACLE就是雙引號(hào),MYSQL默認(rèn)是`反引號(hào); --> <property name="beginningDelimiter" value="`" /> <property name="endingDelimiter" value="`" /> <!-- 格式化java代碼 --> <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/> <!-- 格式化XML代碼 --> <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/> <plugin type="org.mybatis.generator.plugins.SerializablePlugin" /> <plugin type="org.mybatis.generator.plugins.ToStringPlugin" /> <!-- 注釋 --> <commentGenerator > <property name="suppressAllComments" value="false"/><!-- 是否取消注釋 --> <property name="suppressDate" value="true" /> <!-- 是否生成注釋代時(shí)間戳--> </commentGenerator> <!-- jdbc連接 --> <jdbcConnection driverClass="${spring.datasource.driver-class-name}" connectionURL="${spring.datasource.url}" userId="${spring.datasource.username}" password="${spring.datasource.password}" /> <!-- 類型轉(zhuǎn)換 --> <javaTypeResolver> <!-- 是否使用bigDecimal, false可自動(dòng)轉(zhuǎn)化以下類型(Long, Integer, Short, etc.) --> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成實(shí)體類地址 --> <javaModelGenerator targetPackage="com.dgw.mybatisgenerator.entity" targetProject="${mybatis.project}" > <property name="enableSubPackages" value="false"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成mapxml文件 --> <sqlMapGenerator targetPackage="mapper" targetProject="${mybatis.resources}" > <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成mapxml對(duì)應(yīng)client,也就是接口dao --> <javaClientGenerator targetPackage="com.dgw.mybatisgenerator.dao" targetProject="${mybatis.project}" type="XMLMAPPER" > <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- table可以有多個(gè),每個(gè)數(shù)據(jù)庫(kù)中的表都可以寫(xiě)一個(gè)table,tableName表示要匹配的數(shù)據(jù)庫(kù)表,也可以在tableName屬性中通過(guò)使用%通配符來(lái)匹配所有數(shù)據(jù)庫(kù)表,只有匹配的表才會(huì)自動(dòng)生成文件 --> <table tableName="user" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"> <property name="useActualColumnNames" value="false" /> <!-- 數(shù)據(jù)庫(kù)表主鍵 --> <generatedKey column="id" sqlStatement="Mysql" identity="true" /> </table> <!-- <table tableName="book" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"> <property name="useActualColumnNames" value="false" /> &lt;!&ndash; 數(shù)據(jù)庫(kù)表主鍵 &ndash;&gt; <generatedKey column="id" sqlStatement="Mysql" identity="true" /> </table>--> </context></generatorConfiguration>
3: 進(jìn)行配置

右側(cè)Maven處點(diǎn)擊如圖所示位置


測(cè)試陳宮

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • java中抽象類、抽象方法、接口與實(shí)現(xiàn)接口實(shí)例詳解

    java中抽象類、抽象方法、接口與實(shí)現(xiàn)接口實(shí)例詳解

    這篇文章主要給大家介紹了關(guān)于java中抽象類、抽象方法、接口與實(shí)現(xiàn)接口的相關(guān)資料,文中通過(guò)示例代碼將四者介紹的非常詳細(xì),并且簡(jiǎn)單介紹了抽象類和接口的區(qū)別,需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-11-11
  • 一文詳細(xì)springboot實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的整合步驟

    一文詳細(xì)springboot實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的整合步驟

    Spring Boot可以很方便地與MySQL數(shù)據(jù)庫(kù)進(jìn)行整合,下面這篇文章主要給大家介紹了關(guān)于springboot實(shí)現(xiàn)MySQL數(shù)據(jù)庫(kù)的整合步驟,文中通過(guò)圖文以及代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-03-03
  • 深入理解Java中的并發(fā)工具類CountDownLatch

    深入理解Java中的并發(fā)工具類CountDownLatch

    CountDownLatch?作為?Java?中的一個(gè)同步工具類,用于在多線程間實(shí)現(xiàn)協(xié)調(diào)和控制,本文主要來(lái)和大家講解一下JUC?工具類?CountDownLatch的使用,需要的可以參考一下
    2023-07-07
  • 詳解Java編程中線程的掛起、恢復(fù)和終止的方法

    詳解Java編程中線程的掛起、恢復(fù)和終止的方法

    這篇文章主要介紹了詳解Java編程中線程的掛起、恢復(fù)和終止的方法,線程是Java學(xué)習(xí)中的重點(diǎn)和難點(diǎn)知識(shí),需要的朋友可以參考下
    2015-09-09
  • SpringBoot整合gateway全過(guò)程

    SpringBoot整合gateway全過(guò)程

    這篇文章主要介紹了SpringBoot整合gateway全過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • Java中四種訪問(wèn)控制權(quán)限解析(private、default、protected、public)

    Java中四種訪問(wèn)控制權(quán)限解析(private、default、protected、public)

    java當(dāng)中有4種訪問(wèn)修飾限定符privat、default(默認(rèn)訪問(wèn)權(quán)限),protected以及public,本文就詳細(xì)的介紹一下這四種方法的具體使用,感興趣的可以了解一下
    2023-05-05
  • Java導(dǎo)出Excel通用工具類實(shí)例代碼

    Java導(dǎo)出Excel通用工具類實(shí)例代碼

    這篇文章主要給大家介紹了關(guān)于Java導(dǎo)出Excel通用工具類的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • 深入了解java8的foreach循環(huán)

    深入了解java8的foreach循環(huán)

    雖然java8出來(lái)很久了,但是之前用的一直也不多,最近正好學(xué)習(xí)了java8。下面給大家分享java8中的foreach循環(huán),感興趣的朋友一起看看吧
    2017-05-05
  • SpringBoot常見(jiàn)錯(cuò)誤圖文總結(jié)

    SpringBoot常見(jiàn)錯(cuò)誤圖文總結(jié)

    最近在使用idea+Springboot開(kāi)發(fā)項(xiàng)目中遇到一些問(wèn)題,這篇文章主要給大家介紹了關(guān)于SpringBoot常見(jiàn)錯(cuò)誤總結(jié)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • IDEA 2020 無(wú)法啟動(dòng)的解決辦法(啟動(dòng)崩盤)附IDEA 2020 新功能

    IDEA 2020 無(wú)法啟動(dòng)的解決辦法(啟動(dòng)崩盤)附IDEA 2020 新功能

    這篇文章主要介紹了IDEA 2020 無(wú)法啟動(dòng)的解決辦法(啟動(dòng)崩盤)附IDEA 2020 新功能,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04

最新評(píng)論