<?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="D:\Toolsjar\apache-maven-3.6.0\apache-maven-3.6.0\repertory\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar" /> <context id="mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat"> <!-- 生成的Java文件的编码 --> <property name="javaFileEncoding" value="UTF-8"/> <!-- 格式化java代码 --> <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/> <!-- 格式化XML代码 --> <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/> <!--beginningDelimiter和endingDelimiter:指明数据库的用于标记数据库对象名的符号,比如ORACLE就是双引号,MYSQL默认是`反引号;--> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!-- 为了防止生成的代码中有很多注释,比较难看,加入下面的配置控制 --> <commentGenerator> <property name="suppressAllComments" value="true" /> <property name="suppressDate" value="true" /> </commentGenerator> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/mysql?useUnicode=true" userId="root" password="root" /> <!--实体生成路径 --> <javaModelGenerator targetPackage="com.verify.model" targetProject="src/main/java" > <!-- 在targetPackage的基础上,根据数据库的schema再生成一层package,最终生成的类放在这个package下,默认为false --> <!--<property name="enableSubPackages" value="true"/>--> </javaModelGenerator> <!--mapper文件生成路径 --> <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources" /> <!--dao层生成路径 --> <javaClientGenerator targetPackage="com.verify.dao" targetProject="src/main/java" type="XMLMAPPER" /> <table schema="mysql" tableName="db" /> </context> </generatorConfiguration>
maven依赖
<!--逆向工程所需的插件--> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> </configuration> </plugin>
先创建一个xml导入依赖 然后使用生成的插件 生成代码就好了 里面有个坑就是指向mysql的包时别只复制路径后面要记得加上包名