小白刚入手Mac进行Java开发,在使用mybatis-generator自动生成代码的时候一直报没有关闭标签(实际上已经关闭,在win上没有任何问题):


烦请高手指点迷津
Mac中用mybatis-generator生成代码一直报错
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
你知我知皆知 2024-08-06 08:42关注以下回答参考 皆我百晓生、券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。
在使用MyBatis Generator时遇到的问题可能是因为生成的配置文件中的
<jdbcConnection>标签缺少必要的属性。在上述示例中,缺失了driverClass属性。为了修复此错误,请确保将<jdbcConnection>标签添加到generatorConfiguration部分,并设置driverClass属性以匹配您的MySQL连接库。以下是修改后的
generator.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> <!-- 数据库驱动包位置 --> <context id="DB2Tables" targetRuntime="MyBatis3"> <classpathEntry location="/Users/deng/Downloads/mybatis-generator/mysql-connector-iava-5.1.25-bin.iar"/> <commentGenerator suppressDate="true" suppressAllComments="true"/> <!-- 数据库链接URL、用户名、密码 --> <idbcConnection driverClass="com.mysgl.jdbc.priver." connectionURL="idbcamysal://127.0.0.1:3306/test" userId="root" password=""> <property name="driverClass">com.mysql.cj.jdbc.Driver</property> <property name="connectionURL">jdbc:mysql://127.0.0.1:3306/test</property> <property name="username">root</property> <property name="password">your_password_here</property> </idbcConnection> <javaTypeResolver forceBigDecimals="false"/> <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.always.model" targetProject="/Users/deng/mybatis-generator/src"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="com.always.mapping" targetProject="/Users/deng/Downloads/mybatis-generator/src"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成的DAO包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.always.dao" targetproject="/Users/deng/Downloads/mybatis-generator/src"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成哪些表(更改tableTableName和domainObjectName就可以) --> <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> </context> </generatorConfiguration>请注意替换
com.mysql.cj.jdbc.Driver为您实际使用的MySQL JDBC 驱动库的名称。如果您正在使用JDBC 4.x版本,请确保使用com.mysql.jdbc.Driver。此外,您还需要替换your_password_here为您的MySQL数据库的实际用户密码。解决 无用评论 打赏 举报