문제

In my Play2 app, I am trying to retrieve a list of users from one of my database table. The query responsible for this may potentially be empty if there is no row in the database matching the criteria (which is the firstName in our case). That is why I have managed to implement it like this :

    DB.withConnection { implicit connection =>
      SQL("""select u.* from users u
                where u.firstName like '%{firstName}%'
          """).on("firstName" -> firstName).as(userParser *)
    }

this query returns a List[User] but how can I return an Option[List[User]] since this query may not retrieve data corresponding to the provided param (firstName) ?

any help would be appreciated thanks...

도움이 되었습니까?

해결책

You don't need to. If no user is found. The list will simply be empty.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top