在Scala中,+运算符实际上是一个名为+的对象实现的方法.对于Int,来自Int.scala:
/** Returns the sum of this value and `x`. */
def +(x: Int): Int
Run Code Online (Sandbox Code Playgroud)
可以使用中缀表示法调用没有副作用的1-arity方法:
// this
caller method callee
// and this
caller.method(callee)
// are identical, so
1 + 2
// is actually
(1).+(2)
Run Code Online (Sandbox Code Playgroud)
但我无法在Int.scala上找到该语言实际上如何在+方法中执行整数加法.
怎么做?
我正在处理的项目是使用 JHipster 生成的,支持实体过滤,它在底层使用 Spring Data JPA 规范。
模型如下(在JDL中):
entity Student {
name String
}
entity Course {
name String
}
entity Enrollment {
}
entity Attendance {
date LocalDate
}
relationship OneToMany {
Student to Enrollment(student required),
Course to Enrollment(course required),
Enrollment to Attendance(enrollment required)
}
filter all
service all with serviceClass
Run Code Online (Sandbox Code Playgroud)
JHipster 生成用于过滤Attendance的样板enrollmentId,但我想扩展它以能够过滤studentId和courseId。
那么,我如何实现一个可以执行如下查询的规范:
entity Student {
name String
}
entity Course {
name String
}
entity Enrollment {
}
entity …Run Code Online (Sandbox Code Playgroud)