mybatis逆向工程由于路径、驱动版本原因发生错误

1、路径

配置文件、model、mapper目标位置,以及运行代码里所有文件都需要用绝对路径。

2、驱动版本

由于使8.0.17版本的mysql所以不能用5.0.18版本的连接驱动,并且driverClass和connectURL都需要改变

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/vhr?useSSL=false&amp;serverTimezone=UTC" userId="root" password="root">

3、错误代码

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2575)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2311)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
    at org.mybatis.generator.internal.db.ConnectionFactory.getConnection(ConnectionFactory.java:68)
    at org.mybatis.generator.config.Context.getConnection(Context.java:526)
    at org.mybatis.generator.config.Context.introspectTables(Context.java:436)
    at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:222)
    at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:133)
    at GeneratorSqlmap.generator(GeneratorSqlmap.java:27)
    at GeneratorSqlmap.main(GeneratorSqlmap.java:33)
Caused by: java.lang.NullPointerException
    at com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3286)
    at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1987)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1913)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2493)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2526)
    ... 17 more

4、mybatis逆向工程代码

<?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="E:\newVhr\src\main\java\org\liuxiang\vhr\vhrhouduan\mybatis-generator-core-1.3.1\mysql-connector-java-8.0.17.jar"/>
	<context id="DB2Tables"	targetRuntime="MyBatis3">
 <commentGenerator> 

                <property name="suppressAllComments" value="true" /> 

            </commentGenerator>  
		<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/vhr?useSSL=false&amp;serverTimezone=UTC" userId="root" password="aiMONEY157732">
		</jdbcConnection>
		<javaTypeResolver>
			<property name="forceBigDecimals" value="false"/>
		</javaTypeResolver>

		<javaModelGenerator targetPackage="org.javaboy.vhr.model" targetProject="E:\newVhr\src\main\java\org\liuxiang\vhr\vhrhouduan\mybatis-generator-core-1.3.1\src">
			<property name="enableSubPackages" value="true"/>
			<property name="trimStrings" value="true"/>
		</javaModelGenerator>

		<sqlMapGenerator targetPackage="org.javaboy.vhr.mapper" targetProject="E:\newVhr\src\main\java\org\liuxiang\vhr\vhrhouduan\mybatis-generator-core-1.3.1\src">
			<property name="enableSubPackages" value="true"/>
		</sqlMapGenerator>

		<javaClientGenerator type="XMLMAPPER" targetPackage="org.javaboy.vhr.mapper" targetProject="E:\newVhr\src\main\java\org\liuxiang\vhr\vhrhouduan\mybatis-generator-core-1.3.1\src">
			<property name="enableSubPackages" value="true"/>
		</javaClientGenerator>
		
		<table tableName="adjustsalary" domainObjectName="AdjustSalary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="appraise" domainObjectName="Appraise" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="department" domainObjectName="Department" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="employee" domainObjectName="Employee" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="employeeec" domainObjectName="Employeeec" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="employeeremove" domainObjectName="Employeeremove" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="employeetrain" domainObjectName="Employeetrain" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="empsalary" domainObjectName="EmpSalary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="hr" domainObjectName="Hr" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="hr_role" domainObjectName="HrRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="joblevel" domainObjectName="JObLevel" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="menu" domainObjectName="Menu" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		<table tableName="menu_role" domainObjectName="MenuRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="msgcontent" domainObjectName="MsgContent" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="nation" domainObjectName="Nation" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="oplog" domainObjectName="OpLog" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="politicsstatus" domainObjectName="Politicsstatus" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		
		<table tableName="position" domainObjectName="Position" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		
		<table tableName="role" domainObjectName="Role" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="salary" domainObjectName="Salary" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
		
		<table tableName="sysmsg" domainObjectName="SysMsg" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
		enableSelectByExample="false" selectByExampleQueryId="false"></table>
	</context>
</generatorConfiguration>
发布了16 篇原创文章 · 获赞 0 · 访问量 405

猜你喜欢

转载自blog.csdn.net/weixin_43532415/article/details/105586110