gpt4 book ai didi

mysql - [运行时异常 : SqlMappingError(No rows when expecting a single one)]

转载 作者:行者123 更新时间:2023-11-30 23:20:53 26 4
gpt4 key购买 nike

有没有办法让 Scala Anorm 处理空行结果?

我刚收到这个错误:[RuntimeException: SqlMappingError(No rows when expecting a one one)]

我的方法:

def findByEmail(email: String): User = {
DB.withConnection { implicit connection=>
SQL("SELECT * FROM users WHERE email = {email}").on(
'email -> email
).as(User.simple.single)
}
}

最佳答案

您几乎就在那里,不需要使用单打和奇怪的大小写匹配。只需这样做:

def findByEmail(email: String): Option[User] = {
DB.withConnection { implicit connection=>
SQL("SELECT * FROM users WHERE email = {email}").on(
'email -> email
).as(User.simple.singleOpt)
}
}

关于mysql - [运行时异常 : SqlMappingError(No rows when expecting a single one)],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15505088/

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