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();
}
}
 
mybatis-generator 自动生成查询Vo
 
 
上一篇:微信小程序的真机测试


下一篇:Java文件上传与下载