DB2生成表model与mybatis的mapper中的常用方法

阅读更多
  已经用这个工具很久了感觉很方便,该工具会将bd2中的表生成model与mapper以及mapper.xml中的增删改查的常用方法,话不多说,上菜...

1.配置















connectionURL="数据库地址" userId="用户名"
password="密码">




targetProject="E:\test">





targetProject="E:\test">



targetProject="E:\test" type="XMLMAPPER">




enableDeleteByExample="true" enableCountByExample="true"
enableUpdateByExample="true">





2.执行 main方法

package com.***.test;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

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



public class MybatisTool {
    public static void main(String[] args) {
        List warnings = new ArrayList();
        boolean overwrite = true;
        String genCfg = "mbgConfiguration.xml";
        System.out.println(MybatisTool.class.getResource(genCfg));
        File configFile = new File(MybatisTool.class.getResource(genCfg).getFile());
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = null;
        try {
            config = cp.parseConfiguration(configFile);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XMLParserException e) {
            e.printStackTrace();
        }
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = null;
        try {
            myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        } catch (InvalidConfigurationException e) {
            e.printStackTrace();
        }
        try {
            myBatisGenerator.generate(null);
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}





附件为详细的jar包以及代码,谢谢...
  • mybatis表生成model以及mapper.xml.rar (3.6 MB)
  • 下载次数: 7

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