由于第一次写,不知道怎么玩这个格式
导入依赖:
<dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.5</version> </dependency>
然后创建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> <!--数据库驱动--> <classPathEntry location="D:\apache-maven-3.3.9\repository\mysql\mysql-connector-java\5.1.41/mysql-connector-java-5.1.41.jar"/> <context id="my" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="false"/> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- 配置数据库连接 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/manage" userId="root" password=""> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 指定javaBean生成的位置 --> <javaModelGenerator targetPackage="com.zf.entity" targetProject=".\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!--指定sql映射文件生成的位置 --> <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 指定dao接口生成的位置,mapper接口 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.zf.mapper" targetProject=".\src\main\java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- table指定每个表的生成策略 --> <!--数据库表明 实体--> <table tableName="advertisement" domainObjectName="advertisement"></table> <table tableName="feedback" domainObjectName="feedback"></table> <table tableName="feedback_picture" domainObjectName="feedback_picture"></table> <table tableName="flicker_picture" domainObjectName="flicker_picture"></table> <table tableName="flicker_screen" domainObjectName="flicker_screen"></table> <table tableName="immediate_message" domainObjectName="immediate_message"></table> <table tableName="notice" domainObjectName="notice"></table> <table tableName="poster" domainObjectName="poster"></table> <table tableName="union_lecture_hell" domainObjectName="union_lecture_hell"></table> <table tableName="update_package" domainObjectName="update_package"></table> </context> </generatorConfiguration>
启动终端,或者穿件一个java类main方法启动
我用的是java类:
public class generator { public static void main(String[] args) throws Exception{ List<String> warnings = new ArrayList<String>(); boolean overwrite = true; File configFile = new File("generatorConfig.xml"); // xml文件名 ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); }