当前位置: 首页>>代码示例>>Java>>正文


Java GeneratedJavaFile类代码示例

本文整理汇总了Java中org.mybatis.generator.api.GeneratedJavaFile的典型用法代码示例。如果您正苦于以下问题:Java GeneratedJavaFile类的具体用法?Java GeneratedJavaFile怎么用?Java GeneratedJavaFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GeneratedJavaFile类属于org.mybatis.generator.api包,在下文中一共展示了GeneratedJavaFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateService

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private GeneratedJavaFile generateService(IntrospectedTable table) {
    // 获取实体类型
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(table.getBaseRecordType());
    // 获取主键类型
    FullyQualifiedJavaType primaryType = table.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType();
    // 生成 Service 名称
    String service = targetPackage + "." + table.getFullyQualifiedTable().getDomainObjectName() + "Service";
    // 构造 Service 文件
    Interface interfaze = new Interface(new FullyQualifiedJavaType(service));
    // 设置作用域
    interfaze.setVisibility(JavaVisibility.PUBLIC);
    // import
    interfaze.addImportedType(new FullyQualifiedJavaType(baseService));
    interfaze.addImportedType(entityType);
    interfaze.addSuperInterface(new FullyQualifiedJavaType(
            baseService + "<" + entityType.getShortName() + "," + primaryType.getShortName() + ">"));
    ElementHelper.addAuthorTag(interfaze, false);
    return new GeneratedJavaFile(interfaze, targetProject, new DefaultJavaFormatter());
}
 
开发者ID:drtrang,项目名称:mybatis-generator-extension,代码行数:20,代码来源:ServicePlugin.java

示例2: generateServiceImpl

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private GeneratedJavaFile generateServiceImpl(IntrospectedTable table) {
    FullyQualifiedJavaType entityType = new FullyQualifiedJavaType(table.getBaseRecordType());
    FullyQualifiedJavaType primaryType = table.getPrimaryKeyColumns().get(0).getFullyQualifiedJavaType();
    String domainObjectName = table.getFullyQualifiedTable().getDomainObjectName();
    String service = targetPackage + "." + domainObjectName + "Service";
    String serviceImpl = targetPackage + ".impl." + domainObjectName + "ServiceImpl";
    TopLevelClass clazz = new TopLevelClass(new FullyQualifiedJavaType(serviceImpl));
    clazz.addImportedType(new FullyQualifiedJavaType(baseServiceImpl));
    clazz.addImportedType(entityType);
    clazz.addImportedType(new FullyQualifiedJavaType(service));
    clazz.addImportedType(new FullyQualifiedJavaType("org.springframework.stereotype.Service"));
    clazz.addAnnotation("@Service(\"" + firstLetterLowerCase(domainObjectName + "Service") + "\")");
    clazz.setVisibility(JavaVisibility.PUBLIC);
    clazz.setSuperClass(new FullyQualifiedJavaType(
            baseServiceImpl + "<" + entityType.getShortName() + "," + primaryType.getShortName() + ">"));
    clazz.addSuperInterface(new FullyQualifiedJavaType(service));
    ElementHelper.addAuthorTag(clazz, false);
    return new GeneratedJavaFile(clazz, targetProject, new DefaultJavaFormatter());
}
 
开发者ID:drtrang,项目名称:mybatis-generator-extension,代码行数:20,代码来源:ServicePlugin.java

示例3: contextGenerateAdditionalJavaFiles

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {

    List<GeneratedJavaFile> files = new ArrayList<GeneratedJavaFile>();
    if (!isExceted) {
        isExceted = true;
        generatedSuperClient(introspectedTable, files);
        generatedSuperService(introspectedTable, files);
    }

    /**
     * 每个表的service实现
     */
    generatedService(introspectedTable, files);

    return files;
}
 
开发者ID:beeant0512,项目名称:mybatis-generator,代码行数:18,代码来源:BaseClientPlugin.java

示例4: generatedSuperClient

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private void generatedSuperClient(IntrospectedTable introspectedTable, List<GeneratedJavaFile> files) {
    Interface interfaze = new Interface(superClient);
    interfaze.setVisibility(JavaVisibility.PUBLIC);

    generateMethod(introspectedTable, interfaze, true);

    superClient.addTypeArgument(genericType);
    if (generateExample) {
        superClient.addTypeArgument(genericExampleType);
    }

    interfaze.addImportedType(paramAnnotationFqjt);

    GeneratedJavaFile javaFile = new GeneratedJavaFile(interfaze, context.getJavaModelGeneratorConfiguration()
            .getTargetProject(),
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
    files.add(javaFile);

}
 
开发者ID:beeant0512,项目名称:mybatis-generator,代码行数:21,代码来源:BaseClientPlugin.java

示例5: superServiceInterfaceGenerated

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private void superServiceInterfaceGenerated(IntrospectedTable introspectedTable, List<GeneratedJavaFile> files) {
    superServiceInterfaceFqjt = new FullyQualifiedJavaType(superService);
    superServiceInterfaceFqjt.addTypeArgument(new FullyQualifiedJavaType("T"));

    Interface interfaze = new Interface(superServiceInterfaceFqjt);

    interfaze.setVisibility(JavaVisibility.PUBLIC);
    superServiceMethodGenerated(interfaze, introspectedTable);
    if (!addExampleArg) {
        superServiceInterfaceFqjt.addTypeArgument(new FullyQualifiedJavaType("Example"));
    }
    GeneratedJavaFile javaFile = new GeneratedJavaFile(interfaze, context.getJavaModelGeneratorConfiguration()
            .getTargetProject(),
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
    files.add(javaFile);

    superServiceImplementGenerated(introspectedTable, files);
}
 
开发者ID:beeant0512,项目名称:mybatis-generator,代码行数:20,代码来源:BaseJavaFiles.java

示例6: superDaoInterfaceGenerated

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private void superDaoInterfaceGenerated(IntrospectedTable introspectedTable, List<GeneratedJavaFile> files) {
    FullyQualifiedJavaType superDaoInterfaceFqjt = new FullyQualifiedJavaType(superDao);
    superDaoInterfaceFqjt.addTypeArgument(new FullyQualifiedJavaType("T"));

    Interface interfaze = new Interface(superDaoInterfaceFqjt);

    interfaze.setVisibility(JavaVisibility.PUBLIC);
    addExampleArg = superDaoInterfaceMethodGenerated(interfaze, introspectedTable);
    if (addExampleArg) {
        superDaoInterfaceFqjt.addTypeArgument(new FullyQualifiedJavaType("Example"));
    }
    GeneratedJavaFile javaFile = new GeneratedJavaFile(interfaze, context.getJavaModelGeneratorConfiguration()
            .getTargetProject(),
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());
    files.add(javaFile);
}
 
开发者ID:beeant0512,项目名称:mybatis-generator,代码行数:18,代码来源:BaseJavaFiles.java

示例7: superServiceImplementGenerated

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private void superServiceImplementGenerated(IntrospectedTable introspectedTable, List<GeneratedJavaFile> files) {
    FullyQualifiedJavaType serviceImplementFqjt = new FullyQualifiedJavaType(superServiceImpl);
    serviceImplementFqjt.addTypeArgument(new FullyQualifiedJavaType("T"));

    TopLevelClass topLevelClass = new TopLevelClass(serviceImplementFqjt);
    topLevelClass.setVisibility(JavaVisibility.PUBLIC);

    superServiceImplementMethodGenerated(topLevelClass, introspectedTable);
    if (addExampleArg) {
        serviceImplementFqjt.addTypeArgument(new FullyQualifiedJavaType("Example"));
    }
    topLevelClass.addSuperInterface(superServiceInterfaceFqjt);
    topLevelClass.addImportedType(superServiceInterfaceFqjt);
    topLevelClass.setAbstract(true);

    GeneratedJavaFile javaFile = new GeneratedJavaFile(topLevelClass, context.getJavaModelGeneratorConfiguration()
            .getTargetProject(),
            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
            context.getJavaFormatter());

    files.add(javaFile);
}
 
开发者ID:beeant0512,项目名称:mybatis-generator,代码行数:23,代码来源:BaseJavaFiles.java

示例8: generateServiceIface

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
private GeneratedJavaFile generateServiceIface(IntrospectedTable table) {
	String baseName = PluginUtils.getModelTypeShortName(table).replace(getToBeReplace(), "");
	String modelName = PluginUtils.getModelTypeShortName(table);
	String pkName = PluginUtils.getPKTypeShortName(table);

	Interface topclass = new Interface(getServiceIfaceTypeName(baseName));
	topclass.setVisibility(JavaVisibility.PUBLIC);

	topclass.addImportedType(new FullyQualifiedJavaType(PluginUtils.getModelType(table)));
	topclass.addImportedType(new FullyQualifiedJavaType(PluginUtils.getPKType(table)));
	topclass.addImportedType(new FullyQualifiedJavaType(getBaseServiceName()));

	//继承BaseService接口
	String superIfaceName = String.format("%s<%s, %s>", getBaseServiceName(), modelName, pkName);
	topclass.addSuperInterface(new FullyQualifiedJavaType(superIfaceName));

	String targetProject = table.getContext().getJavaClientGeneratorConfiguration().getTargetProject();
	String fileEncoding = table.getContext().getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING);
	JavaFormatter javaFormatter = table.getContext().getJavaFormatter();
	GeneratedJavaFile file = new GeneratedJavaFile(topclass, targetProject, fileEncoding, javaFormatter);

	return file;
}
 
开发者ID:haogrgr,项目名称:haogrgr-projects,代码行数:24,代码来源:ServicePlugin.java

示例9: contextGenerateAdditionalJavaFiles

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
        IntrospectedTable introspectedTable) {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin
                .contextGenerateAdditionalJavaFiles(introspectedTable);
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:13,代码来源:PluginAggregator.java

示例10: generateJavaFiles

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
@Parameters
public static List<GeneratedJavaFile> generateJavaFiles() throws Exception {
    List<GeneratedJavaFile> generatedFiles = new ArrayList<GeneratedJavaFile>();
    generatedFiles.addAll(generateJavaFilesMybatis());
    generatedFiles.addAll(generateJavaFilesIbatis());
    return generatedFiles;
}
 
开发者ID:bandaotixi,项目名称:generator_mybatis,代码行数:8,代码来源:JavaCodeGenerationTest.java

示例11: testGenerate

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
/**
 * 测试具体生成
 */
@Test
public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException {
    // 全局规则增加 DB, tb2 单独规则增加Tt
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TablePrefixPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
        String name = file.getCompilationUnit().getType().getShortName();
        if (name.matches(".*1.*")){
            Assert.assertTrue(name.matches("DB.*"));
        } else {
            Assert.assertTrue(name.matches("Tt.*"));
        }
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:18,代码来源:TablePrefixPluginTest.java

示例12: testGenerateWithoutTemplate

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
/**
 * 测试没有配置模板的情况
 */
@Test
public void testGenerateWithoutTemplate() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator-without-template.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    // 是否在使用系统默认模板
    int count = 0;
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFormattedContent().indexOf("@project https://github.com/itfsw/mybatis-generator-plugin") != -1) {
            count++;
        }
    }
    Assert.assertTrue(count > 0);
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:17,代码来源:CommentPluginTest.java

示例13: testGenerateWithTemplate

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
/**
 * 测试配置了模板参数转换
 */
@Test
public void testGenerateWithTemplate() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    // java中的注释
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFileName().equals("Tb.java")) {
            TopLevelClass topLevelClass = (TopLevelClass) file.getCompilationUnit();
            // addJavaFileComment
            Assert.assertEquals(topLevelClass.getFileCommentLines().get(0), "TestAddJavaFileComment:Tb:" + new SimpleDateFormat("yyyy-MM").format(new Date()));
            // addFieldComment 同时测试 if 判断和 mbg
            Field id = topLevelClass.getFields().get(0);
            Assert.assertEquals(id.getJavaDocLines().get(0), "注释1");
            Assert.assertEquals(id.getJavaDocLines().get(1), MergeConstants.NEW_ELEMENT_TAG);
            // addGeneralMethodComment
            Method cons = topLevelClass.getMethods().get(0);
            Assert.assertEquals(cons.getJavaDocLines().get(0), "addGeneralMethodComment:Tb:tb");
            // addSetterComment
            Method setter = topLevelClass.getMethods().get(5);
            Assert.assertEquals(setter.getJavaDocLines().get(0), "addSetterComment:field1:field1");
        }
    }

    // xml注释
    ObjectUtil xml = new ObjectUtil(myBatisGenerator.getGeneratedXmlFiles().get(0));
    Document doc = (Document) xml.get("document");
    List<Element> els = ((XmlElement) (doc.getRootElement().getElements().get(0))).getElements();
    String comment = ((TextElement) els.get(0)).getContent();
    Assert.assertEquals(comment, "addComment:BaseResultMap");
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:35,代码来源:CommentPluginTest.java

示例14: testNormalPath

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
@Test
public void testNormalPath() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator-without-plugin.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<GeneratedJavaFile> list = myBatisGenerator.getGeneratedJavaFiles();
    for (GeneratedJavaFile file : list){
        if (file.getFileName().equals("TbExample.java")){
            Assert.assertEquals(file.getTargetPackage(), tool.getTargetPackage());
        }
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:13,代码来源:ExampleTargetPluginTest.java

示例15: testConfigPath

import org.mybatis.generator.api.GeneratedJavaFile; //导入依赖的package包/类
@Test
public void testConfigPath() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<GeneratedJavaFile> list = myBatisGenerator.getGeneratedJavaFiles();
    for (GeneratedJavaFile file : list){
        if (file.getFileName().equals("TbExample.java")){
            Assert.assertEquals(file.getTargetPackage(), "com.itfsw.mybatis.generator.plugins.dao.example");
        }
    }
}
 
开发者ID:itfsw,项目名称:mybatis-generator-plugin,代码行数:13,代码来源:ExampleTargetPluginTest.java


注:本文中的org.mybatis.generator.api.GeneratedJavaFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。