Annotation Interface CsvColumn


@Target(FIELD) @Retention(RUNTIME) public @interface CsvColumn
CSV Column - Maps a Java field to a CSV column CSV列 - 将Java字段映射到CSV列

Annotate record components or class fields to specify which CSV column they correspond to. If neither value() nor index() is set, the Java field name is used as the header name.

标注记录组件或类字段以指定它们对应的CSV列。如果既未设置 value() 也未设置 index(),则使用Java字段名作为标题名。

Usage Examples | 使用示例:

public record Employee(
    @CsvColumn("Name") String name,
    @CsvColumn(index = 1) int age,
    @CsvColumn(value = "Role", required = true) String role
) {}
Since:
JDK 25, opencode-base-csv V1.0.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The 0-based column index (-1 = use name matching) 0起始列索引(-1 = 使用名称匹配)
    boolean
    Whether this column is required (binding fails if missing) 此列是否为必需(缺少时绑定失败)
    The CSV header name to bind to (empty = use field name) 要绑定的CSV标题名(空 = 使用字段名)
  • Element Details

    • value

      String value
      The CSV header name to bind to (empty = use field name) 要绑定的CSV标题名(空 = 使用字段名)
      Returns:
      the header name | 标题名
      Default:
      ""
    • index

      int index
      The 0-based column index (-1 = use name matching) 0起始列索引(-1 = 使用名称匹配)
      Returns:
      the column index | 列索引
      Default:
      -1
    • required

      boolean required
      Whether this column is required (binding fails if missing) 此列是否为必需(缺少时绑定失败)
      Returns:
      true if required | 如果必需返回true
      Default:
      false