문제

We can write sqls like following in play2's anorm:

def findById(id: String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id={id}").on('id -> id).as(simple.singleOpt)
}

It uses {xxx} format as the placeholder, and the specify a map 'id->id. Is there anyway to use ? as the placeholder as we do in play1?

I hope I can write it like:

def findById(id:String): Option[Link] = DB.withConnection {implicit connection =>
  SQL("select * from links where id=?").on(id).as(simple.singleOpt)
}

This format is very useful sometimes.

도움이 되었습니까?

해결책

No, currently Anorm uses the Scala symbols for the mapping and you can't use '?'.

This may change in the future, but it is not possible right now.

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