0
我試圖創建一個「演示」付款服務,輸入卡信息並驗證數據庫以確認您輸入的信息是否有效。當前數據庫非常基礎,只是一個Excel電子表格,但目標是在基本驗證完成後進行擴展。 我對編程還很陌生,並且努力研究如何在輸入卡號,cvv2號碼和郵編時如何根據數據庫中保存的信息檢查輸入?以及如果這些信息不正確,錯誤將如何填充。下面是我的倉庫類的代碼至今:根據存儲庫驗證數據輸入
public class DataRepository {
private List<DataRecord> allData = new ArrayList<>();
public DataRepository(String excelFilePath) {
FileInputStream inputStream;
try {
inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet firstSheet = workbook.getSheetAt(0);
Iterator<Row> iterator = firstSheet.iterator();
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue());
break;
}
System.out.print(" - ");
}
System.out.println();
}
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public List<DataRecord> getAllData() {
return allData;
}
public void setAllData(List<DataRecord> allData) {
this.allData = allData;
}
}
感謝您的快速回復,我有一個'PayService'類,它具有此公共布爾isCardNumberValid(){ \t \t返回Boolean.TRUE; \t}冒着聽起來很愚蠢的風險,我正在努力瞭解他們現在如何分享這些信息。爲了將這些信息發送到Excel或數據庫,我需要什麼? –
是的,它似乎是正確的。請記住這個概念。將PayService作爲接口並將PayServiceImpl作爲您正在使用的類(或類似的東西)。或者,我可能不確定你真的在問什麼。 – libik
感謝您的幫助,我認爲如果我是誠實的,我需要在進一步深入之前嘗試並掌握更多的過程 –