[英]how to pass parameter value in controller
I have this code 我有这个代码
class UserController @Inject() (var factory:FactoryHandler) extends Controller {
}
FactoryHandler.scala FactoryHandler.scala
class FactoryHandler(s:String) {
}
how can I pass "s" parameter a value in UserController in playframework-2.4 please help I want to fill this parameter for further tasks 如何在playframework-2.4的UserController中为“ s”参数传递值,请帮助我为后续任务填写此参数
Somehow changing the state of Injected object should be avoided as this Injected object can also be used by some other controller and modified state can lead to unnecessary bugs. 应避免以某种方式更改Injected对象的状态,因为此Injected对象也可以由其他控制器使用,并且修改后的状态可能导致不必要的错误。
An ideal functional solution would be to change this injected class into case class or implement a copy method by yourself in class. 理想的功能解决方案是将自己插入的类更改为case类,或者自己在类中实现复制方法。
case class FactoryHandler(s: String)
class UserController @Inject() (var factory:FactoryHandler) extends Controller {
val updatedFactory = factory.copy(s="Updated Value")
furtherProcessing(updatedFactory)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.