-1
空的情況下,我有以下POST體的例子:處理中階遊戲框架
{ "Id": "123abxy"}
{ "customUrl": "http://www.whiskey.com","Id": "123abxy"}
{ "size": "88", "customUrl": "http://www.whiskey.com","Id": "123abxy"}
與以下端點:
case class aType(
customUrl: Option[String],
Id:Option[String],
size:Option[String]
)
@ResponseBody
def addCompany(
@RequestBody a: aType,
@ModelAttribute("action-context") actionContext: ActionContext
): DeferredResult[Created] = Action[Created]
{
val customUrl = {
a.customUrl
}
val size = {
if (a.size == None) {None}
else Option(a.size.get.toLong)
}
val Id = {
a.Id
}
val handle = register(
customUrl,
Id,
size
).run()
}.runForSpring[Nothing](executors, actionContext)
另外:
def register(
customUrl: Option[String],
Id: Option[String],
size: Option[Long]
)
鑑於上述情況,我想知道正確的方法來處理size
和customUrl
未傳遞int的情況o POST正文。
在這種情況下,由於size
可以是一個值(Long
)或null
和customUrl
可以是String
或null
,我將承擔適當的數據類型來處理,這將是Option[String]
和Option[Long]
爲customUrl
和size
,分別。
我的問題是如何改變if-else
條款來處理null或上述情景String
/Long
,這樣我就可以通過有效的變量進入register(..)
功能?
乾杯,