使用Mybatis逆向工程时候遇到的各种问题

Mybatis逆向工程

Mybatis逆向工程提供了非常方便的代码生成功能,这里就不再赘述,本文主要写一些自己在使用时候遇到的异常报错

targetRuntime报错

targetRuntime in context mybatisGenerator is invalid

这个问题是出现在一开始设置mybatis的时候,遇到这种情况的时候,我们只需要把配置文件中的mybatis改成mybatis3

<generatorConfiguration>
    <context id="testTables" targetRuntime="MyBatis3">
        <commentGenerator>
            
            <property name="suppressAllComments" value="true" />

驱动问题

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’.

com.mysql.jdbc.Driver已经不再使用,更换成最新的驱动就行

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver">

SSL连接问题

WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

提示警告不建议使用没有带服务器身份验证的SSL连接,是在MYSQL5.5.45+, 5.6.26+ and 5.7.6+版本中才有的这个问题。
解决方法:在url连接后面加上useSSL=false就行

jdbc:mysql://localhost:3306/test?useSSL=false

时区问题

The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

在连接字符串后面加上?serverTimezone=UTC
其中UTC是统一标准世界时间。
完整的连接字符串示例:jdbc:mysql://localhost:3306/test?serverTimezone=UTC
或者还有另一种选择:
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8,这个是解决中文乱码输入问题,当然也可以和上面的一起结合:
jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

字符问题

SAXParseException,对实体 “serverTimezone” 的引用必须以 ‘;’ 分隔符结尾。

这种问题就是出现了&在转换的时候不兼容的问题
解决方式:在&后面加上amp;

完整配置文件

附上自己完整的generatorConfig.xml配置文件




<generatorConfiguration>
    <context id="testTables" targetRuntime="MyBatis3">
        <commentGenerator>
            
            <property name="suppressAllComments" value="true" />
        commentGenerator>
        
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/mustlearn?useSSL=false&serverTimezone=CTT&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true" 
                        userId="root"
                        password="123456">
        jdbcConnection>
        

        
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        javaTypeResolver>

        
        <javaModelGenerator targetPackage="po"
                            targetProject=".\src">
            
            <property name="enableSubPackages" value="false" />
            
            <property name="trimStrings" value="true" />
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="mapper"
                         targetProject=".\src">
            
            <property name="enableSubPackages" value="false" />
        sqlMapGenerator>
        
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="mapper"
                             targetProject=".\src">
            
            <property name="enableSubPackages" value="false" />
        javaClientGenerator>
        
        <table tableName="user">table>
        
        

        
    context>
generatorConfiguration>


你可能感兴趣的:(SSM)