mybatis的逆向工程

由数据库的表生成代码,然后生成代码配置文件,指定mubatis表,再执行生成程序。

接下来我们的项目连接数据库可能要用到,看了很多代码,感觉一知半解,继续努力~

<!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="testTables" targetRuntime="MyBatis3">
        <commentGenerator>
                      <property name="suppressAllComments" value="true" />
        </commentGenerator>
           <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://120.25.162.238:3306/mybatis001?characterEncoding=utf-8" 
            userId="root"
            password="123">
        </jdbcConnection>
        <!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
            connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg" 
            userId="yycg"
            password="yycg">
        </jdbcConnection> -->

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


        <javaModelGenerator targetPackage="com.iot.ssm.po"
            targetProject=".\src">
                       <property name="enableSubPackages" value="false" />
                      <property name="trimStrings" value="true" />
        </javaModelGenerator>
                <sqlMapGenerator targetPackage="com.iot.ssm.mapper" 
            targetProject=".\src">
                       <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>
              <javaClientGenerator type="XMLMAPPER"
            targetPackage="com.iot.ssm.mapper" 
            targetProject=".\src">
                       <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
             <table tableName="items"></table>
        <table tableName="orders"></table>
        <table tableName="orderdetail"></table>
        <table tableName="user"></table>
        <!-- <table schema="" tableName="sys_user"></table>
        <table schema="" tableName="sys_role"></table>
        <table schema="" tableName="sys_permission"></table>
        <table schema="" tableName="sys_user_role"></table>
        <table schema="" tableName="sys_role_permission"></table> -->

         <table schema="" tableName="">
            <columnOverride column="" javaType="" />
        </table> -->
    </context>
</generatorConfiguration>

public void generator() throws Exception{

    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
        File configFile = new File("generatorConfig.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);

} 
posted @ 2017-07-04 18:29  宋廷婷  阅读(180)  评论(0编辑  收藏  举报