package dao
import scala.collection.mutable.ListBuffer
import scala.io.Source
class BorrowRecordDAO {def loadBorrowRecords(): ListBuffer[BorrowRecordModel] = {
val borrowRecords = ListBuffer[BorrowRecordModel]()
val lines = Source.fromFile("borrow_records.txt")
for(line <- lines.getLines()){
val Array(userName,bookID,bookName,borrowDate,returnDate) = line.split(",")
borrowRecords += BorrowRecordModel(userName,bookID.toInt,bookName,borrowDate,Some(returnDate))
}
borrowRecords
}
// 写入借阅记录
def saveBorrowRecords(records: ListBuffer[BorrowRecordModel]): Unit = {
val writer = new java.io.PrintWriter("borrow_records.txt")
for(record <- records){
writer.println(record.userName+","+record.bookID+","+record.bookName+","+record.borrowDate+","+record.returnDate.getOrElse(""))
}
writer.close()
}
}
BorrowRecordDAO
yzj2311282024-12-22 11:08
相关推荐
小坏讲微服务6 小时前
Spring Cloud Alibaba 整合 Scala 教程完整使用Kiri霧6 小时前
Scala 循环控制:掌握 while 和 for 循环pale_moonlight1 天前
十、 Scala 应用实践 (上)小坏讲微服务1 天前
SpringCloud整合Scala实现MybatisPlus实现业务增删改查今天没有盐2 天前
Scala Map集合完全指南:从入门到实战应用BD_Marathon3 天前
sbt 编译打包 scala92743 天前
26 trait-多继承详解渣渣盟4 天前
Flink分布式文件Sink实战解析-大头.4 天前
Scala全链路实战:零基础到生产级今天没有盐5 天前
Scala 访问权限详解:private、protected 与 private