0
我有一个应用程序控制器有2个方法。在第一种方法中,我访问数据库并检索表单的下拉元素列表。我将检索到的元素存储在类级变量中。在第二种方法中,如果出现错误,它将显示表单,否则它会显示结果。问题是我的类的变量返回空。请求之间应用程序类变量不可用
class Application extends Controller {
var appList = Seq[AppDetail]()
var countryList = Seq[Country]()
def home(page:Int,filter: String): Action[AnyContent] = Action.async { implicit request =>
val futures = for {
appDetails <- AppDetailsDAO.listAll() //DB retrieve
countries <- CountriesDAO.listAll() //DB retrieve
} yield (appDetails, countries)
futures.map{case (appDetails, countries) => {
appList = appDetails
countryList = countries
Ok(appList, countryList)
}
}
def result(page:Int, filter: String): Action[AnyContent] = Action.async { implicit request =>
analyticForm.bindFromRequest.fold(
formWithErrors => {
Future.successful(BadRequest(html.home(formWithErrors, appList, countryList)) //appList, countryList returns empty
},
analyticData => {
Ok(appList, countryList) //appList, countryList returns empty
}
}
}
你的回答很清楚。感谢您花时间解释它。 – binshi