zoukankan      html  css  js  c++  java
  • mybatis-generator 自动生成查询Vo

    package com.witwicky.plugins;
    
    import org.mybatis.generator.api.GeneratedJavaFile;
    import org.mybatis.generator.api.IntrospectedTable;
    import org.mybatis.generator.api.PluginAdapter;
    import org.mybatis.generator.api.dom.DefaultJavaFormatter;
    import org.mybatis.generator.api.dom.java.JavaVisibility;
    import org.mybatis.generator.api.dom.java.TopLevelClass;
    
    import java.util.Collections;
    import java.util.List;
    
    public class GenQueryVoPlugin extends PluginAdapter {
    
        public GenQueryVoPlugin() {
            super();
        }
    
        public boolean validate(List<String> warnings) {
            return true;
        }
    
        @Override
        public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
            String queryVoName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();
    
            String model = context.getJavaModelGeneratorConfiguration().getTargetPackage();
            String querVoPkgName = properties.getProperty("QUERVO_PKG_NAME", "queryvo");
            String queryVo = join(model.substring(0, model.lastIndexOf(".")), querVoPkgName);
    
            String querVoSuffix = properties.getProperty("QUERVO_VO_SUFFIX", "Vo");
            TopLevelClass root = new TopLevelClass(join(queryVo, queryVoName + querVoSuffix));
            root.addImportedType(model + "." + queryVoName);
            root.setSuperClass(queryVoName);
            root.setVisibility(JavaVisibility.PUBLIC);
    
            String targetProject = context.getJavaClientGeneratorConfiguration().getTargetProject();
            GeneratedJavaFile gjf = new GeneratedJavaFile(root, targetProject, "UTF-8", new DefaultJavaFormatter());
    
            return Collections.singletonList(gjf);
        }
    
        private String join(String... strs) {
            StringBuilder sb = new StringBuilder();
            for (String str : strs) {
                sb.append(str).append(".");
            }
            return sb.deleteCharAt(sb.length() - 1).toString();
        }
    }
    
  • 相关阅读:
    C# 类与类的关系(2)
    如何成为一个优秀的程序员?
    设计模式详细系列教程 (二) 创建型模式
    UML系列 (四) 实战机房收费系统
    UML系列 (三) 四种关系
    HDU 4003 Find Metal Mineral(树形DP+分组背包)
    从零开始的acm竞赛生涯
    2016 ACMICPC ECFinal题解整理
    第四章 复杂选择结构
    第五章 循环结构
  • 原文地址:https://www.cnblogs.com/hfultrastrong/p/10684261.html
Copyright © 2011-2022 走看看