Cox*_*xer 8 sql-server uuid scala
我的数据库条目具有值的UUID(使用Microsoft SQL Server Management Studio提取)
CDF86F27-AFF4-2E47-BABB - 2F46B079E98B
将其加载到我的Scala应用程序后,toString方法会生成此值
276ff8cd-f4af-472e降低-BABB - 2f46b079e98b
这是怎么发生的?当我手边只有裸字符串CDF86F27-AFF4-2E47-BABB-2F46B079E98B时,如何以编程方式创建UUID实例?
相关的Slick代码(前者:表定义,后者:数据库访问对象)
class ChannelTable(tag: Tag) extends Table[ChannelTuple](tag, "Channel") {
def id = column[UUID]("Id", O.PrimaryKey)
def channelId = column[Int]("Channel_Id", O.NotNull)
def timer = column[UUID]("Timer_Id", O.NotNull)
def from = column[Timestamp]("FromTime", O.NotNull)
def to = column[Timestamp]("ToTime", O.NotNull)
def mon = column[Boolean]("Mon", O.NotNull)
def tues = column[Boolean]("Tues", O.NotNull)
def wed = column[Boolean]("Wed", O.NotNull)
def thu = column[Boolean]("Thu", O.NotNull)
def fri = column[Boolean]("Fri", O.NotNull)
def sat = column[Boolean]("Sat", O.NotNull)
def sun = column[Boolean]("Sun", O.NotNull)
def * = (id, channelId, timer, from, to, mon, tues, wed, thu, fri, sat, sun)
}
object ChannelDAO extends EntityDAO[Channel, ChannelTuple] {
private val entities = TableQuery[ChannelTable]
[...]
override def get(id: UUID)(implicit session: Session): Option[Channel] = {
val y = for {
a <- entities if a.id === id
} yield (a)
if (y.list.length > 1) throw new NonUniqueResultException
y.firstOption
}
[...]
}
Run Code Online (Sandbox Code Playgroud)
对我来说效果很好:
> val uuidString = "CDF86F27-AFF4-2E47-BABB-2F46B079E98B"
uuidString: String = CDF86F27-AFF4-2E47-BABB-2F46B079E98B
> java.util.UUID.fromString(uuidString)
res2: java.util.UUID = cdf86f27-aff4-2e47-babb-2f46b079e98b
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3739 次 |
| 最近记录: |