Java Code Examples for org.mybatis.generator.api.MyBatisGenerator#generate()

The following examples show how to use org.mybatis.generator.api.MyBatisGenerator#generate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MapperGeneratorStrategyBase.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
/**
 * 调用 mybatis-generator
 *
 * @param document xml
 */
protected void generateMyBatis3(Document document, GeneratorConfig generatorConfig) {
    List<String> warnings = new ArrayList<>();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    try {
        Configuration config = cp.parseConfiguration(document);

        MyShellCallback shellCallback = new MyShellCallback(true, generatorConfig.isUseMerge());

        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
        myBatisGenerator.generate(null, null, null);
    } catch (InvalidConfigurationException | XMLParserException | InterruptedException | IOException | SQLException e) {
        log.error("生成mapper error", e);
        throw new BizException("导出失败");
    }

    if (!warnings.isEmpty()) {
        warnings.forEach(log::warn);
    }
}
 
Example 2
Source File: Generator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 3
Source File: Generator.java    From HIS with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 4
Source File: Generator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 5
Source File: Generator.java    From HIS with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 6
Source File: Generator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 7
Source File: Generator.java    From macrozheng-mall with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 8
Source File: Generator.java    From HIS with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 9
Source File: MySqlMybatisGenerator.java    From java-master with Apache License 2.0 6 votes vote down vote up
public static void generator() throws Exception {
    List<String> warnings = new ArrayList<>();
    File propFile = ResourceUtils.getFile("classpath:generatorConfig.properties");
    Properties properties = new Properties();
    properties.load(new FileInputStream(propFile));

    String projectPath = new File("").getAbsolutePath();
    properties.put("project.path", projectPath);


    InputStream inputStream = addTableToXml(properties.getProperty("tables"));

    ConfigurationParser cp = new ConfigurationParser(properties, warnings);
    Configuration config = cp.parseConfiguration(inputStream);
    DefaultShellCallback callback = new DefaultShellCallback(true);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    myBatisGenerator.generate(null);
    inputStream.close();
    logger.info("generated warnings:" + warnings);
}
 
Example 10
Source File: Generator.java    From mall-swarm with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 11
Source File: Generator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 12
Source File: Generator.java    From HIS with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 13
Source File: Generator.java    From HIS with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 14
Source File: Generator.java    From mall-learning with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    //MBG 执行过程中的警告信息
    List<String> warnings = new ArrayList<String>();
    //当生成的代码重复时,覆盖原代码
    boolean overwrite = true;
    //读取我们的 MBG 配置文件
    InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    //创建 MBG
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    //执行生成代码
    myBatisGenerator.generate(null);
    //输出警告信息
    for (String warning : warnings) {
        System.out.println(warning);
    }
}
 
Example 15
Source File: MapperGenerate.java    From cjs_ssms with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  List<String> warnings = new ArrayList<>();
  ConfigurationParser cp = new ConfigurationParser(warnings);
  Configuration config = cp.parseConfiguration(
      MapperGenerate.class.getResourceAsStream("/database/mybatis-generator-mapper-config.xml"));

  DefaultShellCallback callback = new DefaultShellCallback(true);
  MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
  myBatisGenerator.generate(null);
}
 
Example 16
Source File: Generator.java    From seata-samples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    InputStream inputStream = Generator.class.getClassLoader().getResourceAsStream("config/generatorConfig.xml");
    ConfigurationParser cp = new ConfigurationParser(warnings);

    Configuration config = cp.parseConfiguration(inputStream);
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config,
            callback, warnings);
    myBatisGenerator.generate(new NullProgressCallback());

}
 
Example 17
Source File: MBGTest.java    From Resource with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception
{
    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    //配置MyBatis generator配置文件
    File configFile = new File("src/main/resources/MyBatisGenerator.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);
}
 
Example 18
Source File: MybatisGenerator.java    From bootshiro with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String today = "2018-03-19";
    long timeEx = 1000*60*60*24;

    SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
    Date now =sdf.parse(today);
    Date d = new Date();

    if(d.getTime()>now.getTime()+timeEx){
        System.err.println("——————未成成功运行——————");
        System.err.println("——————未成成功运行——————");
        System.err.println("本程序具有破坏作用,应该只运行一次,如果必须要再运行,需要修改today变量为今天,如:" + sdf.format(new Date()));
        return;
    }

    List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    InputStream is= MybatisGenerator.class.getClassLoader().getResource("generatorConfig.xml").openStream();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(is);
    is.close();
    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
    myBatisGenerator.generate(null);

    System.out.println("生成代码成功,只能执行一次,以后执行会覆盖掉mapper,pojo,xml 等文件上做的修改");

}
 
Example 19
Source File: GeneratorSqlmap.java    From generatorSqlmapCustom with MIT License 5 votes vote down vote up
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);

    }
 
Example 20
Source File: MyBatisGeneratorTool.java    From mybatis-generator-plugin with Apache License 2.0 3 votes vote down vote up
/**
 * 执行MyBatisGenerator
 * @param before
 * @return
 * @throws SQLException
 * @throws IOException
 * @throws InterruptedException
 */
public MyBatisGenerator generate(IBeforeCallback before) throws Exception {
    before.run();
    MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, new DefaultShellCallback(true), warnings);
    myBatisGenerator.generate(null, null, null, false);
    return myBatisGenerator;
}