1.下载mybatis-generator-core-1.3.5
https://github.com/mybatis/generator/releases
2.解压并进入bin目录
3.下载mysql-connector-java-5.1.40-bin、mybatis-3.4.4至bin目录
4.新建src目录和generatorConfig.xml配置文件
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE generatorConfiguration 3 PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" 4 "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> 5 6 <generatorConfiguration> 7 <!-- 数据库驱动--> 8 <classPathEntry location="mysql-connector-java-5.1.40-bin.jar"/> 9 <context id="DB2Tables" targetRuntime="MyBatis3"> 10 <commentGenerator> 11 <property name="suppressDate" value="true"/> 12 <!-- 是否去除自动生成的注释 true:是 : false:否 --> 13 <property name="suppressAllComments" value="true"/> 14 </commentGenerator> 15 <!--数据库链接URL,用户名、密码 --> 16 <jdbcConnection 17 driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/nutchTest?useSSL=false" userId="root" password="3790137.,lkj"> 18 </jdbcConnection> 19 <javaTypeResolver> 20 <property name="forceBigDecimals" value="false"/> 21 </javaTypeResolver> 22 <!-- 生成模型的包名和位置--> 23 <javaModelGenerator targetPackage="test.domain" targetProject="src"> 24 <property name="enableSubPackages" value="true"/> 25 <property name="trimStrings" value="true"/> 26 </javaModelGenerator> 27 <!-- 生成映射文件的包名和位置--> 28 <sqlMapGenerator targetPackage="test.mapping" targetProject="src"> 29 <property name="enableSubPackages" value="true"/> 30 </sqlMapGenerator> 31 <!-- 生成DAO的包名和位置--> 32 <javaClientGenerator type="XMLMAPPER" targetPackage="test.IDao" targetProject="src"> 33 <property name="enableSubPackages" value="true"/> 34 </javaClientGenerator> 35 <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> 36 <table tableName="crawl_data" domainObjectName="News" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> 37 </context> 38 </generatorConfiguration>
6.命令行下运行;
java -jar mybatis-generator-core-1.3.5.jar -configfile generatorConfig.xml -overwrite
时间: 2024-10-06 15:21:49