2

I'm a java developper for some while. Recently I've started working with play framework (in java, not scala) and what I like about it the most, is the stateless application type. The question I have right now is :

  • since play framework is stateless, can we use static methods everywhere (without having the risk that a user use some information of another user for instance ?) or the static methods in play is the same as static in a ordinary java application. The JVM server side keeps the same info as a classic web application ? It may be a dumb question but thanks for your answers.
4

1 回答 1

1

这不是一个愚蠢的问题。理论上您可以使用所有静态方法,但这不是一个好的编码实践。相反,您可以使用诸如在程序中传递的域对象之类的东西。您可以在传递域对象时更改域对象中的数据,并且它仅在当前执行堆栈的生命周期中存在(当然,除非您将其持久化)。

这将使您的程序保持无状态,并防止您不得不使用所有静态方法。

于 2013-06-30T20:42:23.057 回答