mybatis generator

mbg.xml:

xml version="1.0" encoding="UTF-8"?>
generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">



    id="mysqlTables" targetRuntime="MyBatis3">
        
            name="suppressAllComments" value="true" />
        
        
        driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/ssm_crud" userId="root"
                        password="root">
        

        
            name="forceBigDecimals" value="false" />
        

        
        targetPackage="cn.com.cmbc.crud.bean"
                            targetProject=".\src\main\java">
            name="enableSubPackages" value="true" />
            name="trimStrings" value="true" />
        
        
        targetPackage="mapper" targetProject=".\src\main\resources">
            name="enableSubPackages" value="true" />
        
        
        type="XMLMAPPER"
                             targetPackage="cn.com.cmbc.crud.dao" targetProject=".\src\main\java">
            name="enableSubPackages" value="true" />
        

        
        tableName="tbl_emp" domainObjectName="Employee">
tableName="tbl_dept" domainObjectName="Department">

MBGTest::

package cn.com.cmbc.crud.test;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by yemin on 2017/8/23.
 */
public class MBGTest {
    public static void main (String[] args) throws Exception,XMLParserException{
        List warnings = new ArrayList();
        boolean overwrite = true;
        File configFile = new File("mbg.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);
    }
}

你可能感兴趣的:(spring,mybatis)