Java Code Examples for org.mybatis.generator.api.IntrospectedTable#getRemarks()

The following examples show how to use org.mybatis.generator.api.IntrospectedTable#getRemarks() . 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: MySQLCommentGenerator.java    From mbg-comment with MIT License 6 votes vote down vote up
@Override
public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    String author = properties.getProperty("author");
    String dateFormat = properties.getProperty("dateFormat", "yyyy-MM-dd");
    SimpleDateFormat dateFormatter = new SimpleDateFormat(dateFormat);

    // 获取表注释
    String remarks = introspectedTable.getRemarks();

    topLevelClass.addJavaDocLine("/**");
    topLevelClass.addJavaDocLine(" * " + remarks);
    topLevelClass.addJavaDocLine(" *");
    topLevelClass.addJavaDocLine(" * @author " + author);
    topLevelClass.addJavaDocLine(" * @date   " + dateFormatter.format(new Date()));
    topLevelClass.addJavaDocLine(" */");
}
 
Example 2
Source File: CustomCommentGenerator.java    From BlogManagePlatform with Apache License 2.0 6 votes vote down vote up
private void resolvePrimaryKey(Field field, IntrospectedTable table, IntrospectedColumn column) {
	String columnName = column.getActualColumnName();
	List<IntrospectedColumn> primaryKey = table.getPrimaryKeyColumns();
	String remark = column.getRemarks();
	for (IntrospectedColumn pk : primaryKey) {
		if (columnName.equals(pk.getActualColumnName())) {
			field.addAnnotation("@Id");
			String tableRemark = table.getRemarks();
			if (tableRemark.endsWith("表")) {
				tableRemark = tableRemark.substring(0, tableRemark.length() - 1);
			}
			remark = tableRemark + remark;
			break;
		}
	}
}
 
Example 3
Source File: DefaultCommentGenerator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public void addModelClassComment(TopLevelClass topLevelClass,
        IntrospectedTable introspectedTable) {
    if (suppressAllComments  || !addRemarkComments) {
        return;
    }

    topLevelClass.addJavaDocLine("/**");

    String remarks = introspectedTable.getRemarks();
    if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
        topLevelClass.addJavaDocLine(" * Database Table Remarks:");
        String[] remarkLines = remarks.split(System.getProperty("line.separator")); 
        for (String remarkLine : remarkLines) {
            topLevelClass.addJavaDocLine(" *   " + remarkLine); 
        }
    }
    topLevelClass.addJavaDocLine(" *");

    topLevelClass
            .addJavaDocLine(" * This class was generated by MyBatis Generator.");

    StringBuilder sb = new StringBuilder();
    sb.append(" * This class corresponds to the database table ");
    sb.append(introspectedTable.getFullyQualifiedTable());
    topLevelClass.addJavaDocLine(sb.toString());

    topLevelClass.addJavaDocLine(" */");
}
 
Example 4
Source File: CustomCommentGenerator.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
private void resolveEntityJavadoc(TopLevelClass klass, IntrospectedTable table) {
	String tableRemark = table.getRemarks() == null ? "" : table.getRemarks();
	klass.addJavaDocLine("/**");
	klass.addJavaDocLine(" * @description " + tableRemark);
	klass.addJavaDocLine(" * @table " + table.getFullyQualifiedTable());
	klass.addJavaDocLine(" * @date " + LocalDate.now().toString());
	klass.addJavaDocLine(" */");
}
 
Example 5
Source File: CustomCommentGenerator.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
private void resolveEntityAnnotation(TopLevelClass klass, IntrospectedTable table) {
	String tableRemark = table.getRemarks() == null ? "" : table.getRemarks();
	klass.addAnnotation("@Data");
	klass.addAnnotation("@Entity");
	String description = tableRemark;
	if (description.endsWith("表")) {
		description = description.substring(0, description.length() - 1);
		if (!description.endsWith("信息")) {
			description = description.concat("信息");
		}
	}
	klass.addAnnotation("@Table(name = \"" + table.getFullyQualifiedTable() + "\")");
	klass.addAnnotation("@ApiModel(description = \"" + description + "\")");
}
 
Example 6
Source File: DefaultCommentGenerator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
@Override
public void addModelClassComment(TopLevelClass topLevelClass,
                                 IntrospectedTable introspectedTable) {
    if (suppressAllComments || !addRemarkComments) {
        return;
    }

    StringBuilder sb = new StringBuilder();

    topLevelClass.addJavaDocLine("/**"); //$NON-NLS-1$

    String remarks = introspectedTable.getRemarks();
    if (addRemarkComments && StringUtility.stringHasValue(remarks)) {
        topLevelClass.addJavaDocLine(" * Database Table Remarks:");
        String[] remarkLines = remarks.split(System.getProperty("line.separator"));  //$NON-NLS-1$
        for (String remarkLine : remarkLines) {
            topLevelClass.addJavaDocLine(" *   " + remarkLine);  //$NON-NLS-1$
        }
    }
    topLevelClass.addJavaDocLine(" *"); //$NON-NLS-1$

    topLevelClass
            .addJavaDocLine(" * This class was generated by MyBatis Generator."); //$NON-NLS-1$

    sb.append(" * This class corresponds to the database table "); //$NON-NLS-1$
    sb.append(introspectedTable.getFullyQualifiedTable());
    topLevelClass.addJavaDocLine(sb.toString());

    addJavadocTag(topLevelClass, true);

    topLevelClass.addJavaDocLine(" */"); //$NON-NLS-1$
}
 
Example 7
Source File: MyCommentGenerator.java    From mapper-generator-javafx with Apache License 2.0 4 votes vote down vote up
@Override
public void addModelClassComment(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
    if (suppressAllComments || !addRemarkComments) {
        return;
    }
    //通过这种方式不能直接获取表备注
    String remarks = introspectedTable.getRemarks();
    //获取实体类名称
    String entityName = introspectedTable.getFullyQualifiedTable().getDomainObjectName();

    topLevelClass.addJavaDocLine("");
    //添加导入类的信息
    if (supportSwagger) {
        topLevelClass.addJavaDocLine("import io.swagger.annotations.ApiModel;");
        topLevelClass.addJavaDocLine("import io.swagger.annotations.ApiModelProperty;");
    }
    topLevelClass.addJavaDocLine("import lombok.Getter;");
    topLevelClass.addJavaDocLine("import lombok.Setter;");
    topLevelClass.addJavaDocLine("");

    //添加类注释
    topLevelClass.addJavaDocLine("/**");
    topLevelClass.addJavaDocLine(" * 实体类对应的数据表为:" + introspectedTable.getFullyQualifiedTable());
    topLevelClass.addJavaDocLine(" *");
    if (StringUtils.isNotEmpty(remarks)) {
        topLevelClass.addJavaDocLine(" * " + remarks);
        topLevelClass.addJavaDocLine(" *");
    }
    topLevelClass.addJavaDocLine(" * @author " + author);

    //添加时间
    topLevelClass.addJavaDocLine(" * @date " + getDateString());
    topLevelClass.addJavaDocLine(" */");
    topLevelClass.addJavaDocLine("");
    topLevelClass.addJavaDocLine("@Getter");
    topLevelClass.addJavaDocLine("@Setter");

    if (supportSwagger) {
        topLevelClass.addJavaDocLine("@ApiModel(value =\"" + entityName + "\")");
    }
}
 
Example 8
Source File: HySwaggerMapperPlugin.java    From jvue-admin with MIT License 4 votes vote down vote up
private void swaggerApiAnnotation(TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {
	List<String> annotations = topLevelClass.getAnnotations();
	Iterator i$ = null;
	if (this.swaggerApiEnabled) {
		String apiModel = "io.swagger.annotations.ApiModel";
		String apiModelProperty = "io.swagger.annotations.ApiModelProperty";
		topLevelClass.addImportedType(apiModel);
		topLevelClass.addImportedType(apiModelProperty);
		String remarks = introspectedTable.getRemarks();
		if (StringUtil.isEmpty(remarks)) {
			remarks = "";
		}else{
			remarks = remarks.replaceAll("\n", " ");
		}
		if (remarks.endsWith("表")) {
			remarks = remarks.substring(0, remarks.length() - 1) + "对象";
		}
		remarks = topLevelClass.getType().getShortName() + "(" + remarks + ")";
		topLevelClass.addAnnotation("@ApiModel(\"" + remarks + "\")");
		List<Field> fields = topLevelClass.getFields();
		for (i$ = fields.iterator(); i$.hasNext();) {
			Field field = (Field) i$.next();
			List<IntrospectedColumn> allColumns = introspectedTable.getAllColumns();
			for (IntrospectedColumn introspectedColumn : allColumns) {
				if (field.getName().equals(introspectedColumn.getJavaProperty())) {
					String remark = introspectedColumn.getRemarks();
					if(StringUtil.isEmpty(remark)){
						remark = "";
					}else{
						remark = remark.replaceAll("\n", " ");
					}
					field.addAnnotation("@ApiModelProperty(value =\"" + remark + "\",required = false)");
                    if (!introspectedTable.getPrimaryKeyColumns().contains(introspectedColumn)) {
                        if ("version".equalsIgnoreCase(introspectedColumn.getJavaProperty())) {
                            // 处理乐观锁 2018-04-25
                            topLevelClass.addImportedType(new FullyQualifiedJavaType("tk.mybatis.mapper.annotation.Version"));
                            field.addAnnotation("@Version");
                        }
                    }
				}
	        }
		}
	}
}