本文整理汇总了Java中org.mybatis.generator.api.JavaFormatter类的典型用法代码示例。如果您正苦于以下问题:Java JavaFormatter类的具体用法?Java JavaFormatter怎么用?Java JavaFormatter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JavaFormatter类属于org.mybatis.generator.api包,在下文中一共展示了JavaFormatter类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateServiceIface
import org.mybatis.generator.api.JavaFormatter; //导入依赖的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;
}
示例2: createJavaFormatter
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
/**
* Creates a new Object object.
*
* @param context
* the context
* @return the java formatter
*/
public static JavaFormatter createJavaFormatter(Context context) {
String type = context.getProperty(PropertyRegistry.CONTEXT_JAVA_FORMATTER);
if (!stringHasValue(type)) {
type = DefaultJavaFormatter.class.getName();
}
JavaFormatter answer = (JavaFormatter) createInternalObject(type);
answer.setContext(context);
return answer;
}
示例3: getJavaFormatter
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
/**
* Gets the java formatter.
*
* @return the java formatter
*/
public JavaFormatter getJavaFormatter() {
if (javaFormatter == null) {
javaFormatter = ObjectFactory.createJavaFormatter(this);
}
return javaFormatter;
}
示例4: createJavaFormatter
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
/**
* Creates a new Object object.
*
* @param context
* the context
* @return the java formatter
*/
public static JavaFormatter createJavaFormatter(Context context) {
String type = context.getProperty(PropertyRegistry.CONTEXT_JAVA_FORMATTER);
if (!StringUtility.stringHasValue(type)) {
type = DefaultJavaFormatter.class.getName();
}
JavaFormatter answer = (JavaFormatter) createInternalObject(type);
answer.setContext(context);
return answer;
}
示例5: createJavaFormatter
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
public static JavaFormatter createJavaFormatter(Context context) {
String type = context.getProperty(PropertyRegistry.CONTEXT_JAVA_FORMATTER);
if (!StringUtility.stringHasValue(type)) {
type = DefaultJavaFormatter.class.getName();
}
JavaFormatter answer = (JavaFormatter) createInternalObject(type);
answer.setContext(context);
return answer;
}
示例6: getJavaFormatter
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
public JavaFormatter getJavaFormatter() {
if (javaFormatter == null) {
javaFormatter = ObjectFactory.createJavaFormatter(this);
}
return javaFormatter;
}
示例7: getJavaFormatter
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
public JavaFormatter getJavaFormatter() {
if (javaFormatter == null) {
javaFormatter = ObjectFactory.createJavaFormatter(this);
}
return javaFormatter;
}
示例8: contextGenerateAdditionalJavaFiles
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
System.out.println("===============开始:生成Model子类文件================");
JavaFormatter javaFormatter = context.getJavaFormatter();
List<GeneratedJavaFile> subClassJavaFiles = new ArrayList<GeneratedJavaFile>();
for (GeneratedJavaFile javaFile : introspectedTable.getGeneratedJavaFiles()) {
CompilationUnit unit = javaFile.getCompilationUnit();
FullyQualifiedJavaType baseModelJavaType = unit.getType();
TopLevelClass subModelClass = new TopLevelClass(getSubModelType(baseModelJavaType));
subModelClass.setVisibility(JavaVisibility.PUBLIC);
subModelClass.addImportedType(baseModelJavaType);
subModelClass.setSuperClass(baseModelJavaType);
if (!baseModelJavaType.getFullyQualifiedName().endsWith("Example")) {// 对Example类不能添加序列化版本字段
Field field = new Field("serialVersionUID", new FullyQualifiedJavaType("long"));
field.setStatic(true);
field.setFinal(true);
field.setVisibility(JavaVisibility.PRIVATE);
field.setInitializationString("1L");
subModelClass.addField(field);
}
String targetProject = javaFile.getTargetProject();
FullyQualifiedJavaType subModelJavaType = subModelClass.getType();
String subModelPackageName = subModelJavaType.getPackageName();
try {
GeneratedJavaFile subCLassJavafile = new GeneratedJavaFile(subModelClass, targetProject, javaFormatter);
File subModelDir = shellCallback.getDirectory(targetProject, subModelPackageName);
File subModelFile = new File(subModelDir, subCLassJavafile.getFileName());
// 文件不存在
if (!subModelFile.exists()) {
subClassJavaFiles.add(subCLassJavafile);
}
} catch (ShellException e) {
e.printStackTrace();
}
}
System.out.println("===============结束:生成Model子类文件================");
return subClassJavaFiles;
}
示例9: contextGenerateAdditionalJavaFiles
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
System.out.println("===============开始:生成Mapper文件================");
JavaFormatter javaFormatter = context.getJavaFormatter();
FullyQualifiedJavaType pkType = null;
List<IntrospectedColumn> primaryKeyColumns = introspectedTable.getPrimaryKeyColumns();
if (primaryKeyColumns.isEmpty()) {
pkType = new FullyQualifiedJavaType("java.lang.String");
} else {
pkType = primaryKeyColumns.get(0).getFullyQualifiedJavaType();//TODO:默认不考虑联合主键的情况
System.out.println("primaryKey Type:" + pkType);
}
List<GeneratedJavaFile> mapperJavaFiles = new ArrayList<GeneratedJavaFile>();
for (GeneratedJavaFile javaFile : introspectedTable.getGeneratedJavaFiles()) {
CompilationUnit unit = javaFile.getCompilationUnit();
FullyQualifiedJavaType baseModelJavaType = unit.getType();
String shortName = baseModelJavaType.getShortName();
if (shortName.endsWith("Example")) {// 针对Example类不要生成Mapper
continue;
}
String subModelType = getSubModelType(baseModelJavaType);
String subModelExampleType = subModelType + "Example";
System.out.println("shortName:" + shortName);
String subModelName = shortName.replace(baseModelNamePrefix, "");
Interface mapperInterface = new Interface(daoTargetPackage + "." + subModelName + "Mapper");
mapperInterface.setVisibility(JavaVisibility.PUBLIC);
mapperInterface.addJavaDocLine(" /**");
mapperInterface.addJavaDocLine(" * 由MBG工具自动生成,添加与扩展XML文件中对应的同名方法");
mapperInterface.addJavaDocLine(" **/");
FullyQualifiedJavaType subModelJavaType = new FullyQualifiedJavaType(subModelType);
mapperInterface.addImportedType(subModelJavaType);
FullyQualifiedJavaType subModelExampleJavaType = new FullyQualifiedJavaType(subModelExampleType);
mapperInterface.addImportedType(subModelExampleJavaType);
FullyQualifiedJavaType daoSuperType = new FullyQualifiedJavaType(daoSuperClass);
// 添加泛型支持
daoSuperType.addTypeArgument(subModelJavaType);
daoSuperType.addTypeArgument(subModelExampleJavaType);
daoSuperType.addTypeArgument(pkType);
mapperInterface.addImportedType(daoSuperType);
mapperInterface.addSuperInterface(daoSuperType);
try {
GeneratedJavaFile mapperJavafile = new GeneratedJavaFile(mapperInterface, daoTargetDir, javaFormatter);
File mapperDir = shellCallback.getDirectory(daoTargetDir, daoTargetPackage);
File mapperFile = new File(mapperDir, mapperJavafile.getFileName());
// 文件不存在
if (!mapperFile.exists()) {
mapperJavaFiles.add(mapperJavafile);
}
} catch (ShellException e) {
e.printStackTrace();
}
}
System.out.println("===============结束:生成Mapper文件================");
return mapperJavaFiles;
}
示例10: generateServiceImpl
import org.mybatis.generator.api.JavaFormatter; //导入依赖的package包/类
private GeneratedJavaFile generateServiceImpl(IntrospectedTable table) {
String baseName = PluginUtils.getModelTypeShortName(table).replace(getToBeReplace(), "");
String modelName = PluginUtils.getModelTypeShortName(table);
String pkName = PluginUtils.getPKTypeShortName(table);
TopLevelClass topclass = new TopLevelClass(getServiceImplTypeName(baseName));
topclass.setVisibility(JavaVisibility.PUBLIC);
topclass.addImportedType("org.springframework.stereotype.Service");
topclass.addAnnotation("@Service");
topclass.addImportedType(new FullyQualifiedJavaType(PluginUtils.getModelType(table)));
topclass.addImportedType(new FullyQualifiedJavaType(PluginUtils.getPKType(table)));
topclass.addImportedType(new FullyQualifiedJavaType(getBaseServiceSupportName()));
//继承BaseServiceSupport类
String superClassName = String.format("%s<%s, %s>", getBaseServiceSupportName(), modelName, pkName);
topclass.setSuperClass(superClassName);
//实现接口
if (generateIface()) {
topclass.addImportedType(new FullyQualifiedJavaType(getServiceIfaceTypeName(baseName)));
topclass.addSuperInterface(new FullyQualifiedJavaType(getServiceIfaceTypeName(baseName)));
}
//注入Mapper
topclass.addImportedType("javax.annotation.Resource");
topclass.addImportedType(getServiceImplMapperFieldType(baseName, table));
Field field = new Field();
field.setName(getServiceImplMapperFieldName(baseName));
field.setType(new FullyQualifiedJavaType(getServiceImplMapperFieldType(baseName, table)));
field.setVisibility(JavaVisibility.PRIVATE);
field.addAnnotation("@Resource");
topclass.addField(field);
//实现getMapper方法
Method method = new Method("getMapper");
method.addAnnotation("@Override");
method.setVisibility(JavaVisibility.PUBLIC);
String mrtype = String.format("%s<%s, %s>", getBaseMapperName(), modelName, pkName);
method.setReturnType(new FullyQualifiedJavaType(mrtype));
method.addBodyLine("return " + field.getName() + ";");
topclass.addImportedType(method.getReturnType());
topclass.addMethod(method);
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;
}