如何在 spring 引导中从 属性 文件读取数组表示

How to read array representation from property file in spring boot

我想读取 属性 数组格式的文件。

我有这个 属性 文件:

students.student[0] = ABC
students.student[0].marks[0] = 10
students.student[0].marks[1] = 20
students.student[0].marks[2] = 30
students.student[0].marks[3] = 40
students.student[0].marks[4] = 50
students.student[0].marks[5] = 60
students.student[0].marks[6] = 70

students.student[1] = XYZ
students.student[1].marks[0] = 10
students.student[1].marks[1] = 20
students.student[1].marks[2] = 30
students.student[1].marks[3] = 40
students.student[1].marks[4] = 50
students.student[1].marks[5] = 60
students.student[1].marks[6] = 70

我正在尝试按如下方式阅读此 属性 文件:

@ConfigurationProperties("students")
@PropertySource("classpath:student.properties")
public class StudentProperties{
   List<Student> students = new ArryaList<Student>();
   public static class Student
   {
      String name;
      List<Marks> marks = new ArrayList<Marks>;
      public static class Marks
      {
         int marks;
          //getters and setters
      }     
      //getters and setters
   }
   //getters and setters
 }

但它不是设置值。 如何做到这一点?

虽然可能以某种形式 (Reading a List from properties file and load with spring annotation @Value),但这将被视为滥用 application.properties 文件,该文件旨在用于配置而非数据存储。

我建议您将数据保存在 CSV file, and parse them using one of the many suited libraries, ex - How to easily process CSV file to List<MyClass>

映射 POJO 格式不正确,在 Student class 中 List<Integer>

@ConfigurationProperties("students")
@PropertySource("classpath:student.properties")
public class StudentProperties{
List<Student> student = new ArryaList<Student>();
   public static class Student
      {
         String name;
         List<Integer> marks = new ArrayList<Integer>();

        //getters and setters
     }
     //getters and setters
  }