Mr_DouDo
早睡,身体好
2017-11-15 02:23
采纳率: 100%
浏览 2.6k
已采纳

spring boot 整合mybatis-generator如何搭建和配置

自己搭建了两个demo,按照网上的提示,最终都报 Exception getting jdbc driver,
我用的mysql,驱动依赖都有,因为不用mybatis-generator是能够运行的,可以与数据库连接实现简单的DQL和DML语句,

这是我的项目结构图片说明

下面这是我的generatorConfig.xml文件的配置,





<!--数据库链接地址账号密码 -->
connectionURL="jdbc:mysql://localhost:3306/mydb" userId="root"
password="root" />



<!--生成Model类存放位置 -->
targetProject="src/main/java">



<!--生成映射文件存放位置 -->
targetProject="src/main/java">


targetPackage="com.doudo.mapper" targetProject="src/main/java">


<!--生成对应表及类名 -->

enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false">

下面这是pom.xml代码

<name>AdminLTE</name>
<description></description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.8.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.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-freemarker</artifactId>
    </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>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
        <version>1.9.21</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.5</version>
            <dependencies>
                <dependency>
                    <groupId> mysql</groupId>
                    <artifactId> mysql-connector-java</artifactId>
                    <version> 5.1.39</version>
                </dependency>
                <dependency>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-core</artifactId>
                    <version>1.3.5</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>Generate MyBatis Artifacts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!--允许移动生成的文件 -->
                <verbose>true</verbose>
                <!-- 是否覆盖 -->
                <overwrite>true</overwrite>
                <!-- 自动生成的配置 -->
                <configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
            </configuration>
        </plugin>
    </plugins>
</build>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • congge_1993
    瞭望塔 2017-11-15 06:16
    已采纳

    <?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" >

    location="D:\tools\maven\repository\mysql\mysql-connector-java\5.1.43\mysql-connector-java-5.1.43.jar" />

    <!-- 注释处理 -->




    <!-- jdbc -->
    connectionURL="jdbc:mysql://127.0.0.1:3306/test"
    userId="root" password="" />
    <!-- bean -->
    targetProject="src\main\java" />
    <!-- mapper.xml -->
    targetProject="src\main\resources" />
    <!-- dao -->
    targetProject="src\main\java" type="XMLMAPPER" />
    <!-- table -->

    domainObjectName="TempFileInfo" enableCountByExample="false"
    enableDeleteByExample="false" enableSelectByExample="false"
    enableUpdateByExample="false">


    点赞 评论
  • congge_1993
    瞭望塔 2017-11-15 02:40

    配置文件放置的位置不对吧,指定了mybatis-generator.xml那配置文件也不应该是默认命名了

    点赞 评论
  • airfling
    airfling 2017-11-15 03:08

    你这个应该是生成器找不到mysql的驱动包,你看下你生成器运行的时候使用的依赖里面有没有mysql驱动包

    点赞 评论
  • Mr_DouDo
    早睡,身体好 2017-11-15 03:17

    有没有哪个大神用过spring boot 整合 mybatis-generator的啊,有的话给我看下项目包结构,和几个配置文件,这个问题也许就能解决了

    点赞 评论

相关推荐