Java Code Examples for org.mybatis.generator.api.CommentGenerator#addGeneralMethodComment()
The following examples show how to use
org.mybatis.generator.api.CommentGenerator#addGeneralMethodComment() .
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: MethodGeneratorTool.java From hui-mybatis-generator-plugins with Apache License 2.0 | 6 votes |
/** * 默认的批量新增/更新方法构造器. * * @param interfaze the interfaze * @param introspectedTable the introspected table * @param context the context * @author HuWeihui * @since hui_project v1 */ public static void defaultBatchInsertOrUpdateMethodGen(Integer type ,Interface interfaze,IntrospectedTable introspectedTable, Context context){ Set<FullyQualifiedJavaType> importedTypes = MethodGeneratorTool.importedBaseTypesGenerator(introspectedTable); //List<Entity> FullyQualifiedJavaType listParameterType = FullyQualifiedJavaType.getNewListInstance(); listParameterType.addTypeArgument(introspectedTable.getRules().calculateAllFieldsClass()); String methodName = BATCH_INSERT; //1.batchInsert if (type.equals(UPDATE)){ methodName = BATCH_UPDATE; } Method insertMethod = MethodGeneratorTool.methodGenerator(methodName, JavaVisibility.DEFAULT, FullyQualifiedJavaType.getIntInstance(), new Parameter(listParameterType, PARAMETER_NAME, "@Param(\"" + PARAMETER_NAME + "\")")); CommentGenerator commentGenerator = context.getCommentGenerator(); commentGenerator.addGeneralMethodComment(insertMethod, introspectedTable); interfaze.addImportedTypes(importedTypes); interfaze.addMethod(insertMethod); }
Example 2
Source File: MysqlPaginationPlugin.java From server-boilerplate with MIT License | 6 votes |
private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) { CommentGenerator commentGenerator = context.getCommentGenerator(); Field field = new Field(); field.setVisibility(JavaVisibility.PROTECTED); field.setType(PrimitiveTypeWrapper.getIntegerInstance()); field.setName(name); commentGenerator.addFieldComment(field, introspectedTable); topLevelClass.addField(field); char c = name.charAt(0); String camel = Character.toUpperCase(c) + name.substring(1); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("set" + camel); method.addParameter(new Parameter(PrimitiveTypeWrapper.getIntegerInstance(), name)); method.addBodyLine("this." + name + "=" + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(PrimitiveTypeWrapper.getIntegerInstance()); method.setName("get" + camel); method.addBodyLine("return " + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 3
Source File: AbstractDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 6 votes |
/** * Gets the constructor clone. * * @param commentGenerator * the comment generator * @param type * the type * @param introspectedTable * the introspected table * @return the constructor clone */ public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) { configure(); Method answer = new Method(); answer.setConstructor(true); answer.setName(type.getShortName()); answer.setVisibility(constructorTemplate.getVisibility()); for (Parameter parm : constructorTemplate.getParameters()) { answer.addParameter(parm); } for (String bodyLine : constructorTemplate.getBodyLines()) { answer.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) { answer.addException(fqjt); } commentGenerator.addGeneralMethodComment(answer, introspectedTable); return answer; }
Example 4
Source File: AbstractDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 6 votes |
public final Method getConstructorClone(CommentGenerator commentGenerator, FullyQualifiedJavaType type, IntrospectedTable introspectedTable) { configure(); Method answer = new Method(); answer.setConstructor(true); answer.setName(type.getShortName()); answer.setVisibility(constructorTemplate.getVisibility()); for (Parameter parm : constructorTemplate.getParameters()) { answer.addParameter(parm); } for (String bodyLine : constructorTemplate.getBodyLines()) { answer.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : constructorTemplate.getExceptions()) { answer.addException(fqjt); } commentGenerator.addGeneralMethodComment(answer, introspectedTable); return answer; }
Example 5
Source File: MybatisPageTools.java From DouBiNovel with Apache License 2.0 | 5 votes |
private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) { CommentGenerator commentGenerator = context.getCommentGenerator(); Field field = new Field(); field.setVisibility(JavaVisibility.PROTECTED); field.setType(FullyQualifiedJavaType.getIntInstance()); field.setName(name); field.setInitializationString("-1"); commentGenerator.addFieldComment(field, introspectedTable); topLevelClass.addField(field); char c = name.charAt(0); String camel = Character.toUpperCase(c) + name.substring(1); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("set" + camel); method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), name)); method.addBodyLine("this." + name + "=" + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName("get" + camel); method.addBodyLine("return " + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 6
Source File: MybatisPageTools.java From DouBiNovel with Apache License 2.0 | 5 votes |
private void addPage(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { CommentGenerator commentGenerator = context.getCommentGenerator(); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("setPage"); method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "page")); method.addParameter(new Parameter(FullyQualifiedJavaType.getIntInstance(), "size")); method.addBodyLine("this.limitStart = page * size;this.limitEnd = size;"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 7
Source File: MybatisPageTools.java From DouBiNovel with Apache License 2.0 | 5 votes |
private void addPageTemplate(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { CommentGenerator commentGenerator = context.getCommentGenerator(); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("pageByExample"); FullyQualifiedJavaType exampleType = new FullyQualifiedJavaType(introspectedTable.getExampleType()); FullyQualifiedJavaType baseQueryType = new FullyQualifiedJavaType("com.diligrp.shop.constant.BaseQuery"); FullyQualifiedJavaType pageTmplType = new FullyQualifiedJavaType("com.diligrp.shop.constant.PageTemplate"); String recordType = introspectedTable.getBaseRecordType(); method.setReturnType(pageTmplType); method.addParameter(new Parameter(exampleType, "example")); method.addParameter(new Parameter(baseQueryType, "baseQuery")); StringBuffer code = new StringBuffer(32); code.append("int count = this.countByExample(example);\n"); code.append("List<" + recordType + "> list = this.selectByExample(example);\n"); code.append("com.diligrp.shop.constant.PageTemplate<" + recordType + "> pageTemplate = com.diligrp.shop.constant.PageTemplate.build();\n "); code.append("pageTemplate.setTotalSize(count);\n"); code.append("pageTemplate.setList(list);\n"); code.append("if(baseQuery != null){"); code.append("pageTemplate.setCurrPage(baseQuery.getCurrent());\n"); code.append("pageTemplate.setPageSize(baseQuery.getSize());\n"); code.append("}"); code.append("return pageTemplate;"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 8
Source File: OracelPageLimitPlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 5 votes |
private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) { CommentGenerator commentGenerator = context.getCommentGenerator(); Field field = new Field(); field.setVisibility(JavaVisibility.PROTECTED); field.setType(FullyQualifiedJavaType.getIntInstance()); field.setName(name); field.setInitializationString("-1"); commentGenerator.addFieldComment(field, introspectedTable); topLevelClass.addField(field); char c = name.charAt(0); String camel = Character.toUpperCase(c) + name.substring(1); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("set" + camel); method.addParameter(new Parameter(FullyQualifiedJavaType .getIntInstance(), name)); method.addBodyLine("this." + name + "=" + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName("get" + camel); method.addBodyLine("return " + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 9
Source File: MySQLPageLimitPlugin.java From hui-mybatis-generator-plugins with Apache License 2.0 | 5 votes |
private void addLimit(TopLevelClass topLevelClass, IntrospectedTable introspectedTable, String name) { CommentGenerator commentGenerator = context.getCommentGenerator(); Field field = new Field(); field.setVisibility(JavaVisibility.PROTECTED); field.setType(FullyQualifiedJavaType.getIntInstance()); field.setName(name); field.setInitializationString("-1"); commentGenerator.addFieldComment(field, introspectedTable); topLevelClass.addField(field); char c = name.charAt(0); String camel = Character.toUpperCase(c) + name.substring(1); Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("set" + camel); method.addParameter(new Parameter(FullyQualifiedJavaType .getIntInstance(), name)); method.addBodyLine("this." + name + "=" + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setReturnType(FullyQualifiedJavaType.getIntInstance()); method.setName("get" + camel); method.addBodyLine("return " + name + ";"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 10
Source File: AbstractDAOTemplate.java From mybatis-generator-core-fix with Apache License 2.0 | 5 votes |
/** * Gets the method clones. * * @param commentGenerator * the comment generator * @param introspectedTable * the introspected table * @return the method clones */ public final List<Method> getMethodClones( CommentGenerator commentGenerator, IntrospectedTable introspectedTable) { configure(); List<Method> answer = new ArrayList<Method>(); for (Method oldMethod : methods) { Method method = new Method(); for (String bodyLine : oldMethod.getBodyLines()) { method.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) { method.addException(fqjt); } for (Parameter parm : oldMethod.getParameters()) { method.addParameter(parm); } method.setConstructor(oldMethod.isConstructor()); method.setFinal(oldMethod.isFinal()); method.setStatic(oldMethod.isStatic()); method.setName(oldMethod.getName()); method.setReturnType(oldMethod.getReturnType()); method.setVisibility(oldMethod.getVisibility()); commentGenerator.addGeneralMethodComment(method, introspectedTable); answer.add(method); } return answer; }
Example 11
Source File: AbstractDAOTemplate.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
public final List<Method> getMethodClones( CommentGenerator commentGenerator, IntrospectedTable introspectedTable) { configure(); List<Method> answer = new ArrayList<Method>(); for (Method oldMethod : methods) { Method method = new Method(); for (String bodyLine : oldMethod.getBodyLines()) { method.addBodyLine(bodyLine); } for (FullyQualifiedJavaType fqjt : oldMethod.getExceptions()) { method.addException(fqjt); } for (Parameter parm : oldMethod.getParameters()) { method.addParameter(parm); } method.setConstructor(oldMethod.isConstructor()); method.setFinal(oldMethod.isFinal()); method.setStatic(oldMethod.isStatic()); method.setName(oldMethod.getName()); method.setReturnType(oldMethod.getReturnType()); method.setVisibility(oldMethod.getVisibility()); commentGenerator.addGeneralMethodComment(method, introspectedTable); answer.add(method); } return answer; }
Example 12
Source File: CustomPlugin.java From mybatis-generator-plus with Apache License 2.0 | 5 votes |
/** * 修改Example类,添加分页支持 * * @param topLevelClass * @param introspectedTable */ private void addPage(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { CommentGenerator commentGenerator = context.getCommentGenerator(); //.add offset Field Field offsetField = new Field(); offsetField.setVisibility(JavaVisibility.PROTECTED); offsetField.setType(new FullyQualifiedJavaType("java.lang.Long")); offsetField.setName("offset"); commentGenerator.addFieldComment(offsetField, introspectedTable); topLevelClass.addField(offsetField); //.add limit Field Field limitField = new Field(); limitField.setVisibility(JavaVisibility.PROTECTED); limitField.setType(new FullyQualifiedJavaType("java.lang.Long")); limitField.setName("limit"); commentGenerator.addFieldComment(limitField, introspectedTable); topLevelClass.addField(limitField); //.add end Field Field endField = new Field(); endField.setVisibility(JavaVisibility.PROTECTED); endField.setType(new FullyQualifiedJavaType("java.lang.Long")); endField.setName("end"); commentGenerator.addFieldComment(endField, introspectedTable); topLevelClass.addField(endField); //.add setPagination method Method method = new Method(); method.setVisibility(JavaVisibility.PUBLIC); method.setName("setPagination"); method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "offset")); method.addParameter(new Parameter(new FullyQualifiedJavaType("long"), "limit")); method.addBodyLine("this.offset = offset;"); method.addBodyLine("this.limit = limit;"); method.addBodyLine("this.end = offset + limit;"); commentGenerator.addGeneralMethodComment(method, introspectedTable); topLevelClass.addMethod(method); }
Example 13
Source File: EnumTypeStatusPlugin.java From mybatis-generator-plugin with Apache License 2.0 | 4 votes |
public InnerEnum generateEnum(CommentGenerator commentGenerator, IntrospectedTable introspectedTable) { String enumName = FormatTools.upFirstChar(column.getJavaProperty()); InnerEnum innerEnum = new InnerEnum(new FullyQualifiedJavaType(enumName)); commentGenerator.addEnumComment(innerEnum, introspectedTable); innerEnum.setVisibility(JavaVisibility.PUBLIC); innerEnum.setStatic(true); // 生成枚举 for (EnumItemInfo item : this.items) { innerEnum.addEnumConstant(item.getName() + "(" + item.getValue() + ", " + item.getComment() + ")"); } // 生成属性和构造函数 Field fValue = new Field("value", column.getFullyQualifiedJavaType()); fValue.setVisibility(JavaVisibility.PRIVATE); fValue.setFinal(true); commentGenerator.addFieldComment(fValue, introspectedTable); innerEnum.addField(fValue); Field fName = new Field("name", FullyQualifiedJavaType.getStringInstance()); fName.setVisibility(JavaVisibility.PRIVATE); fName.setFinal(true); commentGenerator.addFieldComment(fName, introspectedTable); innerEnum.addField(fName); Method mInc = new Method(enumName); mInc.setConstructor(true); mInc.addBodyLine("this.value = value;"); mInc.addBodyLine("this.name = name;"); mInc.addParameter(new Parameter(fValue.getType(), "value")); mInc.addParameter(new Parameter(fName.getType(), "name")); commentGenerator.addGeneralMethodComment(mInc, introspectedTable); FormatTools.addMethodWithBestPosition(innerEnum, mInc); // 获取value的方法 Method mValue = JavaElementGeneratorTools.generateGetterMethod(fValue); commentGenerator.addGeneralMethodComment(mValue, introspectedTable); FormatTools.addMethodWithBestPosition(innerEnum, mValue); Method mValue1 = JavaElementGeneratorTools.generateGetterMethod(fValue); mValue1.setName("value"); commentGenerator.addGeneralMethodComment(mValue1, introspectedTable); FormatTools.addMethodWithBestPosition(innerEnum, mValue1); // 获取name的方法 Method mName = JavaElementGeneratorTools.generateGetterMethod(fName); commentGenerator.addGeneralMethodComment(mName, introspectedTable); FormatTools.addMethodWithBestPosition(innerEnum, mName); return innerEnum; }
Example 14
Source File: FormatTools.java From mybatis-generator-plugin with Apache License 2.0 | 2 votes |
/** * 替换已有方法注释 * @param commentGenerator * @param method * @param introspectedTable */ public static void replaceGeneralMethodComment(CommentGenerator commentGenerator, Method method, IntrospectedTable introspectedTable) { method.getJavaDocLines().clear(); commentGenerator.addGeneralMethodComment(method, introspectedTable); }