Java Code Examples for org.mybatis.generator.api.CommentGenerator#addFieldComment()

The following examples show how to use org.mybatis.generator.api.CommentGenerator#addFieldComment() . 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: MysqlPaginationPlugin.java    From server-boilerplate with MIT License 6 votes vote down vote up
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 2
Source File: AbstractDAOTemplate.java    From mybatis-generator-core-fix with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the field clones.
 *
 * @param commentGenerator
 *            the comment generator
 * @param introspectedTable
 *            the introspected table
 * @return the field clones
 */
public final List<Field> getFieldClones(CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Field> answer = new ArrayList<Field>();
    for (Field oldField : fields) {
        Field field = new Field();

        field.setInitializationString(oldField.getInitializationString());
        field.setFinal(oldField.isFinal());
        field.setStatic(oldField.isStatic());
        field.setName(oldField.getName());
        field.setType(oldField.getType());
        field.setVisibility(oldField.getVisibility());
        commentGenerator.addFieldComment(field, introspectedTable);
        answer.add(field);
    }

    return answer;
}
 
Example 3
Source File: AbstractDAOTemplate.java    From mybatis-generator-plus with Apache License 2.0 6 votes vote down vote up
public final List<Field> getFieldClones(CommentGenerator commentGenerator,
        IntrospectedTable introspectedTable) {
    configure();
    List<Field> answer = new ArrayList<Field>();
    for (Field oldField : fields) {
        Field field = new Field();

        field.setInitializationString(oldField.getInitializationString());
        field.setFinal(oldField.isFinal());
        field.setStatic(oldField.isStatic());
        field.setName(oldField.getName());
        field.setType(oldField.getType());
        field.setVisibility(oldField.getVisibility());
        commentGenerator.addFieldComment(field, introspectedTable);
        answer.add(field);
    }

    return answer;
}
 
Example 4
Source File: MybatisPageTools.java    From DouBiNovel with Apache License 2.0 5 votes vote down vote up
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 5
Source File: OracelPageLimitPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
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: MySQLPageLimitPlugin.java    From hui-mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
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 7
Source File: CustomPlugin.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
/**
 * 修改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 8
Source File: EnumTypeStatusPlugin.java    From mybatis-generator-plugin with Apache License 2.0 4 votes vote down vote up
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;
}