org.mybatis.generator.api.MyBatisGenerator Java Examples

The following examples show how to use org.mybatis.generator.api.MyBatisGenerator. 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: 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 #2
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 #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 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 #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 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 #7
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 #8
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 #9
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 #10
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 #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 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 #13
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 #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: 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 #16
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 #17
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 #18
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 #19
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 #20
Source File: Generator.java    From xmall 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 #21
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 #22
Source File: Generator.java    From macrozheng 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 #23
Source File: Generator.java    From server 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 #24
Source File: MyBatisGeneratorTest.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Test(expected=InvalidConfigurationException.class)
public void testGenerateIbatis2() throws Exception {
    List<String> warnings = new ArrayList<String>();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2.xml"));
        
    DefaultShellCallback shellCallback = new DefaultShellCallback(true);
    
    try {
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
        myBatisGenerator.generate(null);
    } catch (InvalidConfigurationException e) {
        assertEquals(1, e.getErrors().size());
        throw e;
    }
}
 
Example #25
Source File: Generator.java    From mall 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 #26
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 #27
Source File: MyBatisGeneratorTest.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
@Test(expected=InvalidConfigurationException.class)
public void testGenerateMyBatis3() throws Exception {
    List<String> warnings = new ArrayList<String>();
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigMyBatis3.xml"));
        
    DefaultShellCallback shellCallback = new DefaultShellCallback(true);
    
    try {
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
        myBatisGenerator.generate(null);
    } catch (InvalidConfigurationException e) {
        assertEquals(2, e.getErrors().size());
        throw e;
    }
}
 
Example #28
Source File: MapperAnnotationPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试配置Repository
 * @throws Exception
 */
@Test
public void testWithRepository() throws Exception{
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/MapperAnnotationPlugin/mybatis-generator-with-repository.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof Interface && compilationUnit.getType().getShortName().endsWith("Mapper")) {
            Interface interfaze = (Interface) compilationUnit;

            Assert.assertEquals(interfaze.getAnnotations().size(), 2);
            Assert.assertEquals(interfaze.getAnnotations().get(0), "@Mapper");
            Assert.assertEquals(interfaze.getAnnotations().get(1), "@Repository");
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper")));
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.springframework.stereotype.Repository")));
        }
    }
}
 
Example #29
Source File: LombokPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试具体生成(只有keys的特殊情况,尽量使用Builder)
 */
@Test
public void testGenerateWithOnlyKeys() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LombokPlugin/mybatis-generator-with-only-keys.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof TopLevelClass) {
            TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
            String name = topLevelClass.getType().getShortName();
            if (name.equals("TbOnlyKeysKey")){
                Assert.assertTrue(topLevelClass.getAnnotations().contains("@Builder"));
            }
        }
    }
}
 
Example #30
Source File: BugFixedTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试domainObjectRenamingRule和
 */
@Test
public void bug0004() throws Exception {
    DBHelper.createDB("scripts/BugFixedTest/bug-0004.sql");
    // 规则 ^T 替换成空,也就是去掉前缀
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/bug-0004.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        String name = file.getCompilationUnit().getType().getShortName();
        if (!name.matches("B.*")) {
            Assert.assertTrue(false);
        }
        if (name.endsWith("Example")) {
            Assert.assertEquals(file.getCompilationUnit().getType().getPackageName(), "com.itfsw.dao.example");
        }
    }
}