亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

在SpringBoot項(xiàng)目中利用maven的generate插件

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

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

在項(xiàng)目中增加 maven 依賴

  1. - mybatis-spring-boot-starter
  2. - mysql-connector-java
  3. - mybatis-generator-maven-plugin 插件 自動(dòng)讀取 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ū)動(dòng)-->
    <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 項(xiàng)目中application.properties 配置

  • mybatis.mapper-locations 用來(lái)指定mapper 存放路徑
  • spring.datasource.username 用來(lái)指定 用戶名
  • spring.datasource.password 用來(lái)指定密碼
  • spring.datasource.driver-class-name 用來(lái)指定鏈接驅(qū)動(dòng)
  • spring.datasource.url 用來(lái)指定鏈接路由地址
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

此項(xiàng)內(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>
  <!-- 本地?cái)?shù)據(jù)庫(kù)驅(qū)動(dòng)程序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ù)庫(kù)的相關(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>
    <!-- 實(shí)體類生成的位置 -->
    <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 雙擊運(yùn)行

SpringBootMyBatis 使用

在 service 的實(shí)現(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();
  }
}

啟動(dòng)SpringBoot WEB項(xiàng)目后 訪問(wèn)

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

總結(jié)

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

相關(guān)文章

  • RabbitMQ下載與安裝教程

    RabbitMQ下載與安裝教程

    RabbitMQ是實(shí)現(xiàn)了高級(jí)消息隊(duì)列協(xié)議(AMQP)的開(kāi)源消息代理軟件(亦稱面向消息的中間件),這篇文章給大家介紹RabbitMQ下載與安裝教程,感興趣的朋友跟隨小編一起看看吧
    2024-02-02
  • 如何實(shí)現(xiàn)Java中一個(gè)簡(jiǎn)單的LinkedList

    如何實(shí)現(xiàn)Java中一個(gè)簡(jiǎn)單的LinkedList

    LinkedList與ArrayList都是List接口的具體實(shí)現(xiàn)類。下面將介紹如何實(shí)現(xiàn)一個(gè)簡(jiǎn)單的LinkedList,具有很好的參考價(jià)值,下面跟著小編一起來(lái)看下吧
    2017-02-02
  • SpringBoot解決ajax跨域問(wèn)題的方法

    SpringBoot解決ajax跨域問(wèn)題的方法

    這篇文章主要為大家詳細(xì)介紹了SpringBoot解決ajax跨域問(wèn)題的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • 如何基于Jenkins構(gòu)建Docker鏡像

    如何基于Jenkins構(gòu)建Docker鏡像

    這篇文章主要介紹了基于Jenkins構(gòu)建Docker鏡像,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • logback 實(shí)現(xiàn)給變量指定默認(rèn)值

    logback 實(shí)現(xiàn)給變量指定默認(rèn)值

    這篇文章主要介紹了logback 實(shí)現(xiàn)給變量指定默認(rèn)值操作,具有很好的參考家價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • Java遞歸尋路實(shí)現(xiàn),你真的理解了嗎

    Java遞歸尋路實(shí)現(xiàn),你真的理解了嗎

    遞歸就是一個(gè)過(guò)程或函數(shù)在其定義或說(shuō)明中有直接或間接調(diào)用自身的一種方法,它通常把一個(gè)大型復(fù)雜的問(wèn)題層層轉(zhuǎn)化為一個(gè)與原問(wèn)題相似的規(guī)模較小的問(wèn)題來(lái)求解,需要的朋友可以參考下
    2021-08-08
  • java接口語(yǔ)法以及與類的關(guān)系詳解

    java接口語(yǔ)法以及與類的關(guān)系詳解

    接口在JAVA編程語(yǔ)言中是一個(gè)抽象類型,是抽象方法的集合,接口通常以interface來(lái)聲明。一個(gè)類通過(guò)繼承接口的方式,從而來(lái)繼承接口的抽象方法
    2021-10-10
  • MyBatis找不到mapper文件的實(shí)現(xiàn)

    MyBatis找不到mapper文件的實(shí)現(xiàn)

    這篇文章主要介紹了MyBatis找不到mapper文件的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-10-10
  • @JsonSerialize序列化注解的使用

    @JsonSerialize序列化注解的使用

    這篇文章主要介紹了@JsonSerialize序列化注解的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • Springboot2集成pagehelper過(guò)程圖解

    Springboot2集成pagehelper過(guò)程圖解

    這篇文章主要介紹了springboot2集成pagehelper過(guò)程圖解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03

最新評(píng)論