gpt4 book ai didi

scala - Lift:如何使这些关系多态?

转载 作者:行者123 更新时间:2023-12-04 06:33:38 26 4
gpt4 key购买 nike

我有一个条目
它应该与三个“列表”之一有关,称它们为 ListA ListB ListC
我无法弄清楚如何使用 LongMappedMapper 做到这一点。
那我怎么能这样做呢?

我想让 List 有多个条目,而不必为每种列表指定 listX 关系。
所以不是 :

class Entry ...{
object listA extends LongMappedMapper(this,ListA)
object listB extends LongMappedMapper(this,ListB)
...
}

我想要这样的东西:
class Entry ...{
object list extends PolyLongMappedMapper(this,ListA,ListB,ListC)
//PolyLongMappedMapper i the example mapper what i want
...
}

或者:
class Entry ...{
object list extends PolyLongMappedMapper(this,BaseListTrait)
//where BaseListTrait is a Trait shared by all List classes
//PolyLongMappedMapper i the example mapper what i want
...
}

Lift 框架中有什么东西是我想要的吗?什么可与 PolyLongMappedMapper 相媲美?
或者有没有优雅的方法来解决这个问题?

最佳答案

您可以通过以下方式执行此操作:

class A extends LongKeyedMapper[A] with IdPK {
object entry extends LongMappedMapper(this, Entry)
...

class B extends LongKeyedMapper[B] with IdPK {
object entry extends LongMappedMapper(this, Entry)
...

class C extends LongKeyedMapper[C] with IdPK {
object entry extends LongMappedMapper(this, Entry)
...

class Entry extends LongKeyedMapper[Entry] with IdPK {
def aList = A.findAll(By(A.entry, this))
def bList = B.findAll(By(B.entry, this))
def cList = C.findAll(By(C.entry, this))
...

你的 list 是:
e.aList, e.bList, e.cList

什么时候:
val e: Entry

埃塔姆。

关于scala - Lift:如何使这些关系多态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5098464/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com