最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

在SpringBoot項目中利用maven的generate插件

 更新時間:2019年01月03日 09:48:33   作者:staHuri  
今天小編就為大家分享一篇關(guān)于在SpringBoot項目中利用maven的generate插件,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

使用maven 插件 generate生成MyBatis相關(guān)文件

在項目中增加 maven 依賴

  1. - mybatis-spring-boot-starter
  2. - mysql-connector-java
  3. - mybatis-generator-maven-plugin 插件 自動讀取 resources 下的generatorConfig.xml 文件
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.wangSpringBoot</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>demo</name>
  <description>Demo project for Spring Boot</description>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.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-configuration-processor</artifactId>
      <optional>true</optional>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.16.18</version>
      <scope>provided</scope>
    </dependency>
    <!--熱部署-->
    <dependency>
<groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
    </dependency>
    <!--test-->
    <dependency>
<groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
    <!--MyBatis-->
    <dependency>
<groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>1.3.1</version>
    </dependency>
    <!--Mysql JDBC驅(qū)動-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
<groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <fork>true</fork>
        </configuration>
      </plugin>
      <plugin>
<groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.7</version>
        <executions>
          <execution>
            <id>Generate MyBatis Artifacts</id>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
            <version>2.3.4</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
    <resources>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
        </includes>
      </resource>
      <resource>
<directory>src/main/resources</directory>
        <includes>
          <include>**/*.*</include>
        </includes>
      </resource>
      <resource>
<directory>src/main/webapp</directory>
        <targetPath>META-INF/resources</targetPath>
        <includes>
          <include>**/*.*</include>
        </includes>
      </resource>
    </resources>
  </build>
</project>

SpringBoot 項目中application.properties 配置

  • mybatis.mapper-locations 用來指定mapper 存放路徑
  • spring.datasource.username 用來指定 用戶名
  • spring.datasource.password 用來指定密碼
  • spring.datasource.driver-class-name 用來指定鏈接驅(qū)動
  • spring.datasource.url 用來指定鏈接路由地址
mybatis.mapper-locations=classpath:com/wangspringboot/demo/mapper/*.xml
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/wt?useUnicode=true&characterEncoding=utf8&useSSL=false

resources 下配置 generatorConfig.xml

此項內(nèi)容為直接修改相關(guān)配置即可

<?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>
  <!-- 本地數(shù)據(jù)庫驅(qū)動程序jar包的全路徑 -->
  <classPathEntry
      location="D:\Program Files\MavenRepository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/>
  <context id="context" targetRuntime="MyBatis3">
    <commentGenerator>
      <property name="suppressAllComments" value="false"/>
      <property name="suppressDate" value="true"/>
    </commentGenerator>
    <!-- 數(shù)據(jù)庫的相關(guān)配置 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/wt" userId="root"
            password="root"/>
    <javaTypeResolver>
      <property name="forceBigDecimals" value="false"/>
    </javaTypeResolver>
    <!-- 實體類生成的位置 -->
    <javaModelGenerator targetPackage="com.wangspringboot.demo.model" targetProject="src/main/java">
      <property name="enableSubPackages" value="false"/>
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>
    <!-- *Mapper.xml 文件的位置 -->
    <sqlMapGenerator targetPackage="com.wangspringboot.demo.mapper" targetProject="src/main/java">
      <property name="enableSubPackages" value="false"/>
    </sqlMapGenerator>
    <!-- Mapper 接口文件的位置 -->
    <javaClientGenerator targetPackage="com.wangspringboot.demo.mapper" targetProject="src/main/java"
               type="XMLMAPPER">
      <property name="enableSubPackages" value="false"/>
    </javaClientGenerator>
    <!-- 相關(guān)表的配置-->
    <table tableName="t"
        domainObjectName="Tq"
        enableCountByExample="false"
        enableUpdateByExample="false"
        enableDeleteByExample="false"
        enableSelectByExample="false"
        selectByExampleQueryId="false"
    />
  </context>
</generatorConfiguration>

創(chuàng)建相關(guān)目錄

查看插件

執(zhí)行

選中maven 下 generator 雙擊運行

SpringBootMyBatis 使用

在 service 的實現(xiàn)類上添加 @Service 注解

@Service
public class TqServiceImpl implements TqService {
  @Autowired
  private TqMapper tqmapper;
  @Override
  public Tq insTq() {
    Tq t = new Tq();
    t.setZ(12.0);
    t.setY(12.0);
    t.setX(12.0);
    tqmapper.insert(t);
    return t;
  }
}

相關(guān)調(diào)用

@RestController
public class MyBatisController {
  @Autowired
  private TqService tqService;
  @GetMapping("/boot/tq")
  public Object tq(){
    return tqService.insTq();
  }
}

啟動SpringBoot WEB項目后 訪問

{
x: 12,
y: 12,
z: 12
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

相關(guān)文章

  • Java利用Sping框架編寫RPC遠(yuǎn)程過程調(diào)用服務(wù)的教程

    Java利用Sping框架編寫RPC遠(yuǎn)程過程調(diào)用服務(wù)的教程

    這篇文章主要介紹了Java利用Sping框架編寫RPC遠(yuǎn)程過程調(diào)用服務(wù)的教程,包括項目管理工具M(jìn)aven的搭配使用方法,需要的朋友可以參考下
    2016-06-06
  • 使用Spring自身提供的地址匹配工具匹配URL操作

    使用Spring自身提供的地址匹配工具匹配URL操作

    這篇文章主要介紹了使用Spring自身提供的地址匹配工具匹配URL操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-09-09
  • MyBatis分頁查詢返回list的時候出現(xiàn)null的問題

    MyBatis分頁查詢返回list的時候出現(xiàn)null的問題

    這篇文章主要介紹了MyBatis分頁查詢返回list的時候出現(xiàn)null的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-07-07
  • Spring Boot Web 靜態(tài)文件緩存處理的方法

    Spring Boot Web 靜態(tài)文件緩存處理的方法

    本篇文章主要介紹了Spring Boot Web 靜態(tài)文件緩存處理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-02-02
  • 聊聊Spring Cloud Cli 初體驗

    聊聊Spring Cloud Cli 初體驗

    這篇文章主要介紹了聊聊Spring Cloud Cli 初體驗,SpringBoot CLI 是spring Boot項目的腳手架工具。非常具有實用價值,需要的朋友可以參考下
    2018-04-04
  • Java詳細(xì)講解IO流的Writer與Reader操作

    Java詳細(xì)講解IO流的Writer與Reader操作

    Writer與Reader類不能直接調(diào)用,需要使用多帶的方法調(diào)用它們的子類,在他們的前邊加上一個File即可如(FileWriter或FileReader)的多態(tài)方法進(jìn)行其調(diào)用,并且他們也是抽象類調(diào)用需要連接接口Exception,它們的優(yōu)點在于可以直接寫入或讀出內(nèi)容,不需要使用byte轉(zhuǎn)八進(jìn)制
    2022-05-05
  • spring接口通過配置支持返回多種格式(xml,json,html,excel)

    spring接口通過配置支持返回多種格式(xml,json,html,excel)

    這篇文章主要給大家介紹了關(guān)于spring接口如何通過配置支持返回多種格式(xml,json,html,excel)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • Java e.printStackTrace()案例講解

    Java e.printStackTrace()案例講解

    這篇文章主要介紹了Java e.printStackTrace()案例講解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • 如何利用IDEA快速生成實體類

    如何利用IDEA快速生成實體類

    這篇文章主要介紹了如何利用IDEA快速生成實體類問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • SpringBoot API接口超時時間的五種配置方式詳解

    SpringBoot API接口超時時間的五種配置方式詳解

    在開發(fā)API接口時,配置API接口的超時時間是一項非常重要的任務(wù),SpringBoot中有多種方式可以配置API接口的超時時間,下面小編就為大家介紹一下吧
    2025-03-03

最新評論

上高县| 保康县| 特克斯县| 报价| 穆棱市| 辛集市| 精河县| 沅陵县| 安福县| 股票| 南昌市| 麟游县| 惠东县| 靖宇县| 桂东县| 吉隆县| 芜湖县| 肃南| 永和县| 开阳县| 丰都县| 霍林郭勒市| 通化县| 临猗县| 扎赉特旗| 新昌县| 正镶白旗| 类乌齐县| 达孜县| 平谷区| 拉萨市| 金乡县| 邵阳市| 栾川县| 信丰县| 玉环县| 平山县| 彭山县| 盘山县| 贵州省| 卓资县|