mybatis生成逆向文件及mysql得版本问题

首先考虑到你的mysql的版本问题和你引入的jar包,因为这个不对的化配置就不能连接到数据库。

**

1.如果你使用的是mysql5的版本的化

那你对应的jar包可能是mysql-connector-java-5.1.25.jar。
所以你的连接的配置你要写出这样的
url=jdbc:mysql://127.0.0.1:3306/test
driverClassName=com.mysql.jdbc.Driver

2.但是如果你用的是mysql8

你对应的jar包可能是 mysql-connector-java-8.0.11.jar。
那么你就要这样写你的配置
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/edu1?useSSL=false&serverTimezone=UTC
但是你在generatorConfig.xml配置文件中要按下面得写法,要对特殊符号转义

3.接下来是generatorConfig.xml 的配置文件

<?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>
    <!--数据库驱动-->
    <classPathEntry
            location="C:\Users\MSI-PC\.m2\repository\mysql\mysql-connector-java\8.0.11\mysql-connector-java-8.0.11.jar"/>
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接地址账号密码-->
        <jdbcConnection
                driverClass="com.mysql.jdbc.Driver"
                connectionURL="jdbc:mysql://localhost:3306/edu1?useSSL=false&amp;serverTimezone=UTC"
                userId="root"
                password="123">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成Model类存放位置-->
        <javaModelGenerator targetPackage="com.yuxiu.edu.model" targetProject="./src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="com.yuxiu.edu.mapper" targetProject="./src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.yuxiu.edu.mapper" targetProject="./src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--生成对应表及类名-->
        <table tableName="t_course" domainObjectName="Course" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
       <!-- <table tableName="t_department" domainObjectName="Department" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="t_employee" domainObjectName="Employee" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="t_salary_detail" domainObjectName="SalaryDetail" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="t_student" domainObjectName="Student" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>
        <table tableName="t_user" domainObjectName="User" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false"></table>-->
    </context>
</generatorConfiguration>

下面得是你得pom文件得配置

 <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
  </dependency>
<!--这个是放在plugins标签下的-->
<!--MyBatis自动生成工具插件-->
      <plugin>
           <groupId>org.mybatis.generator</groupId>
           <artifactId>mybatis-generator-maven-plugin</artifactId>
           <version>1.3.2</version>
           <configuration>
               <!--配置文件的位置-->
               <configurationFile>src\main\resources\generatorConfig.xml</configurationFile>
               <verbose>true</verbose>
               <overwrite>true</overwrite>
           </configuration>
           <executions>
               <execution>
                   <id>Generate MyBatis Artifacts</id>
                   <goals>
                       <goal>generate</goal>
                   </goals>
               </execution>
           </executions>
       </plugin>

下面是你的配置maven配置在这里插入图片描述
在你配置好之后你可以点击你的如下按钮就可以自动生成了
在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值