您的位置:首页 > 健康 > 养生 > html样式代码大全_做网站公司哪家靠谱_百度推广怎么操作_谷歌的推广是怎么样的推广

html样式代码大全_做网站公司哪家靠谱_百度推广怎么操作_谷歌的推广是怎么样的推广

2025/1/5 20:25:52 来源:https://blog.csdn.net/2401_87076475/article/details/144871824  浏览:    关键词:html样式代码大全_做网站公司哪家靠谱_百度推广怎么操作_谷歌的推广是怎么样的推广
html样式代码大全_做网站公司哪家靠谱_百度推广怎么操作_谷歌的推广是怎么样的推广

BookDAO
package org.app
package dao
import org.app.modeis.UserMode 
import scala.collection.mutable.ListBuffe 
class UserDAO {
  // 加载所有的用户
  def loadUsers(): ListBuffer[UserModel] = {
    val users = new ListBuffer[UserModel]()
    val source = scala.io.Source.fromFile("users.txt")
    for(line <- source.getLines()){
      val Array(username, password, role) = line.split(",")
      // 实例化一个用户,保存到List
      users += UserModel(username, password, role)
    }
    // 关闭连接
    source.close()
    users
  }
  def saveUsers(users: ListBuffer[UserModel]): Unit = {
    val writer = new java.io.PrintWriter(new java.io.File("users.txt"))
    for (user <- users) {
      writer.println(user.username+ "," + user.password + "," + user.role)
    }
    writer.close()
  }
}
BorrowRecordDAO
package org.app
package dao
import org.app.modeis.BorrowRecordModel
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 parts=line.split(",")
      borrowRecords += BorrowRecordModel(
        parts(0),
        parts(1).toInt,
        parts(2),
        parts(3),
        if (parts.length>4) Some(parts(4)) else None
      )
      }
        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()
  }
}
UserDAO
package org.app
package dao
import org.app.modeis.UserModel
import scala.collection.mutable.ListBuffer
class UserDAO {
  // 加载所有的用户
  def loadUsers(): ListBuffer[UserModel] = {
    val users = new ListBuffer[UserModel]()
    val source = scala.io.Source.fromFile("users.txt")
    for(line <- source.getLines()){
      val Array(username, password, role) = line.split(",")
      // 实例化一个用户,保存到List
      users += UserModel(username, password, role)
    }
    // 关闭连接
    source.close()
    users
  }
  def saveUsers(users: ListBuffer[UserModel]): Unit = {
    val writer = new java.io.PrintWriter(new java.io.File("users.txt"))
    for (user <- users) {
      writer.println(user.username+ "," + user.password + "," + user.role)
    }
    writer.close()
  }
}

 

 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com