Ejemplo n.º 1
0
 /**
  * 给字段添加数据库备注
  *
  * @param field
  * @param introspectedTable
  * @param introspectedColumn
  */
 public void addFieldComment(
     Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
   if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
     field.addJavaDocLine("/**");
     StringBuilder sb = new StringBuilder();
     sb.append(" * ");
     sb.append(introspectedColumn.getRemarks());
     field.addJavaDocLine(sb.toString());
     field.addJavaDocLine(" */");
   }
   // 添加注解
   if (field.isTransient()) {
     // @Column
     field.addAnnotation("@Transient");
   }
   for (IntrospectedColumn column : introspectedTable.getPrimaryKeyColumns()) {
     if (introspectedColumn == column) {
       field.addAnnotation("@Id");
       break;
     }
   }
   String column = introspectedColumn.getActualColumnName();
   if (StringUtility.stringContainsSpace(column)
       || introspectedTable.getTableConfiguration().isAllColumnDelimitingEnabled()) {
     column =
         introspectedColumn.getContext().getBeginningDelimiter()
             + column
             + introspectedColumn.getContext().getEndingDelimiter();
   }
   if (!column.equals(introspectedColumn.getJavaProperty())) {
     // @Column
     field.addAnnotation("@Column(name = \"" + column + "\")");
   }
   if (introspectedColumn.isIdentity()) {
     if (introspectedTable
         .getTableConfiguration()
         .getGeneratedKey()
         .getRuntimeSqlStatement()
         .equals("JDBC")) {
       field.addAnnotation("@GeneratedValue(generator = \"JDBC\")");
     } else {
       field.addAnnotation("@GeneratedValue(strategy = GenerationType.IDENTITY)");
     }
   } else if (introspectedColumn.isSequenceColumn()) {
     field.addAnnotation(
         "@SequenceGenerator(name=\"\",sequenceName=\""
             + introspectedTable.getTableConfiguration().getGeneratedKey().getRuntimeSqlStatement()
             + "\")");
   }
 }
Ejemplo n.º 2
0
  public void addFieldComment(
      Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
    StringBuilder sb = new StringBuilder();

    field.addJavaDocLine("/**");

    field.addJavaDocLine(" * " + introspectedColumn.getRemarks());

    if (detailComment) {
      field.addJavaDocLine(" * 默认值: " + introspectedColumn.getDefaultValue());
      field.addJavaDocLine(" * 长  度: " + introspectedColumn.getLength());
    }

    field.addJavaDocLine(" */"); // $NON-NLS-1$
  }
Ejemplo n.º 3
0
  public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
    if (suppressAllComments) {
      return;
    }

    StringBuilder sb = new StringBuilder();

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

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

    addJavadocTag(field, false);

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