我是 Scala 和 Play 框架的新手。我必须创建一个“联系人”模块,但出现以下错误:
type mismatch found : Unit required: play.api.mvc.Result
contactVal.save()
where contactVal is defined as
val contactVal = new Contact(service) where service is
val service = new ExchangeService()
如何保存新的 EWS 联系人?
我的代码:
def add = Action(parse.json) {
implicit r=>
val contactVal = new Contact(service)
val userId = (r.body \ "userId").asOpt[String].getOrElse("")
val contactId = (r.body \ "id").asOpt[String].getOrElse("")
val givenName = (r.body \ "givenName").asOpt[String].getOrElse("")
val fName = (r.body \ "fName").asOpt[String].getOrElse("")
val lName = (r.body \ "lName").asOpt[String].getOrElse("")
val displayName = (r.body \ "displayName").asOpt[String].getOrElse("")
val emailId1 = (r.body \ "emailId1").asOpt[String].getOrElse("")
val streetB = (r.body \ "streetB").asOpt[String].getOrElse("")
val cityB = (r.body \ "cityB").asOpt[String].getOrElse("")
val stateB = (r.body \ "stateB").asOpt[String].getOrElse("")
val postalcodeB = (r.body \ "postalcodeB").asOpt[String].getOrElse("")
val countryB = (r.body \ "countryB").asOpt[String].getOrElse("")
val phoneHome = (r.body \ "phoneHome").asOpt[Int].getOrElse("")
val bday = (r.body \ "bday").asOpt[String].getOrElse("")
contactVal.setGivenName(givenName)
contactVal.setNickName(fName)
contactVal.setSurname(lName)
contactVal.setDisplayName(displayName)
val bdayDate= new Date()
bdayDate.setDate(bday.toInt)
contactVal.setBirthday(bdayDate)
contactVal.save()
}