Csv 解析 根据标题行进行解析

This commit is contained in:
Liuyang 2025-01-13 18:00:21 +08:00
parent 7abd3d5e96
commit fc56bbc6ed

View File

@ -84,8 +84,20 @@ public class DataSetReadFileUtils {
// 动态读取当行长度与标题行长度相等时
if (line.length == headers.length) {
// 获取系统列索引
int systemIndex = getIndex(headers, "system");
// 获取问题列索引
int questionIndex = getIndex(headers, "question");
// 获取答案列索引
int answerIndex = getIndex(headers, "answer");
// 存储系统列的值
String systemValue = systemIndex == -1? "" : line[systemIndex];
// 存储问题列的值
String questionValue = questionIndex == -1? "" : line[questionIndex];
// 存储答案列的值
String answerValue = answerIndex == -1? "" : line[answerIndex];
// 根据标题行找到相应列的索引创建 CsvDataSetVO 对象
CsvDataSetVO dataSetVO = new CsvDataSetVO(line[getIndex(headers, "system")], line[getIndex(headers, "question")], line[getIndex(headers, "answer")]);
CsvDataSetVO dataSetVO = new CsvDataSetVO(systemValue, questionValue, answerValue);
// 将对象添加到列表中
dataSetVos.add(dataSetVO);
}