1

是否可以在 Lift 中定义一个无符号映射整数?我找不到任何关于它的信息。

class Project extends LongKeyedMapper[Project] with IdPK {
    def getSingleton = Project
    ...
    object budget extends MappedInt(this) // should be unsigned!
    ...
}
4

1 回答 1

0

由于 scala 或 java 中没有无符号整数,您所能做的就是编写运行时检查。像这样的东西应该这样做:(还没有测试过)

object budget extends MappedInt(this) {
  override def validations = {
    ((value:Int) =>
      if (value < 0)
        FieldError(fieldOwner, Text("Budget must not be negative"))::Nil
      else
        Nil)
    :: super.validations
  }
}
于 2011-07-30T12:05:12.337 回答