GeneratorSqlmap使用方法

GeneratorSqlmap自动生成mybatis映射文件和domian实体类

1.主程序中加载main方法,通过main方法生成实体类以及映射文件

public class GeneratorSqlmap {

    public void generator() throws Exception{

        List warnings = new ArrayList();
        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);

    } 
    public static void main(String[] args) throws Exception {
        try {
            GeneratorSqlmap generatorSqlmap = new GeneratorSqlmap();
            generatorSqlmap.generator();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}




2.配置文件generatorConfig.xml配置内容

<generatorConfiguration>
    <context id="testTables" targetRuntime="MyBatis3">
        <commentGenerator>
            
            <property name="suppressAllComments" value="true" />
        commentGenerator>
        
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://localhost:3306/hhwy-demo" userId="root"
            password="root">
        jdbcConnection>
        

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

        
        <javaModelGenerator targetPackage="demo.domain"
            targetProject=".\src">
            
            <property name="enableSubPackages" value="false" />
            
            <property name="trimStrings" value="true" />
        javaModelGenerator>
        
        <sqlMapGenerator targetPackage="demo.mapper" 
            targetProject=".\src">
            
            <property name="enableSubPackages" value="false" />
        sqlMapGenerator>
        
        <javaClientGenerator type="XMLMAPPER"
            targetPackage="demo.mapper" 
            targetProject=".\src">
            
            <property name="enableSubPackages" value="false" />
        javaClientGenerator>
        
       <table schema="" tableName="u_task">table>
        <table schema="" tableName="u_info">table>
        <table schema="" tableName="u_note">table>


        
    context>
generatorConfiguration>

你可能感兴趣的:(java,EE部分技术)