Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 动态替换嵌套对象的字段值_Java_Scala_Reflection_Scalatest - Fatal编程技术网

Java 动态替换嵌套对象的字段值

Java 动态替换嵌套对象的字段值,java,scala,reflection,scalatest,Java,Scala,Reflection,Scalatest,我正在尝试为我的scala应用程序编写集成测试(使用akka http)。我遇到了一个问题,我找不到解决办法 我的案例分类如下: case class Employee(id:Long, name:String, departmentId:Long, createdDate:Timestamp) extends BaseEntity case class EmployeeContainer(employee:Employee, department:Department) extends Ba

我正在尝试为我的
scala
应用程序编写集成测试(使用
akka http
)。我遇到了一个问题,我找不到解决办法

我的案例分类如下:

case class Employee(id:Long, name:String, departmentId:Long, createdDate:Timestamp) extends BaseEntity
case class EmployeeContainer(employee:Employee, department:Department)  extends BaseEntity
我有一个这样的方法

trait BaseTrait[E<:BaseEntity, C <: BaseEntity]{
    def getById(id:Long): Future[List[C]] = {
       //query from db and return result.
    }

    def save(obj:E) = {
      //set the createDate field to the current timestamp
      //insert into database
    }

}

trait-BaseTrait[E您可能需要为of使用一些。您的主要问题是您直接调用数据库:
val-emp-Employee){
覆盖def getById(id:Long)={
为了{
瓦伦普
class MyDao extends BaseTrait[Employee, EmployeeContainer] {
  override def getById(id:Long) = {
      for {
      val emp <- getFromDb(id)
      val dept <- DeptDao.getFromDb(emp.departmentId)
      val container = EmployeeContainer(emp,dept)
      } yield(container)
   }
}
    class MyDao extends BaseTrait[Employee, EmployeeContainer](val dbCall: Long => Employee) {
  override def getById(id:Long) = {
      for {
      val emp <- dbCall(id)
      val dept <- DeptDao.getFromDb(emp.departmentId)
      val container = EmployeeContainer(emp,dept)
      } yield(container)
   }
   }