简体   繁体   English

播放框架2-静态方法

[英]play framework 2 - static methods

I'm a java developper for some while. 我有一段时间是Java开发人员。 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. 最近,我开始使用play框架(在Java中而不是Scala中),而我最喜欢的是无状态应用程序类型。 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. 由于play框架是无状态的,因此我们可以在所有地方使用静态方法(例如,没有用户使用其他用户的某些信息的风险吗?),或者静态方法与普通java应用程序中的static方法相同。 The JVM server side keeps the same info as a classic web application ? JVM服务器端是否保留与经典Web应用程序相同的信息? It may be a dumb question but thanks for your answers. 这可能是一个愚蠢的问题,但感谢您的回答。

It's not a dumb question. 这不是一个愚蠢的问题。 You could theoretically use all static methods but it is not a good coding practice. 从理论上讲,您可以使用所有静态方法,但这不是一个好的编码实践。 Instead you can use something like domain objects that you pass around your program. 相反,您可以使用在程序中传递的域对象之类的东西。 You can change the data in a domain object as it is passed around and it only exists for the life cycle of your current execution stack (that is of course unless you persist it). 您可以在域对象中传递数据时更改它,并且该数据仅在当前执行堆栈的生命周期中存在(当然,除非您坚持执行,否则就不存在)。

This will keep your program stateless and prevent you having to use all static methods. 这将使程序保持无状态,并避免必须使用所有静态方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 播放框架JavaScript路线+非静态方法 - Play framework javascript routes + non static methods 在Play中调用静态方法! 框架控制器不起作用 - Calling static methods in Play! framework controller doesn't work 每个 Play 框架 Web 请求是否都使用新的依赖注入控制器实例处理,那么静态控制器方法呢? - Is each Play framework web request handled with a new dependency injected controller instance, but then what about static controller methods? 在Play框架2.1.4中使用Helpers.callAction和不带静态方法的控制器 - using Helpers.callAction with controllers without static methods in Play framework 2.1.4 在Controller方法中抛出异常Play框架? - Throwing exceptions in Controller methods Play framework? 如何在Java和Play Framework中使用HTTP方法 - How to use HTTP Methods in JAVA with Play Framework 500访问静态资源时出错:Play框架 - 500 Error for accessing static resources: Play Framework Java中play框架中静态控制器与非静态控制器的区别 - Difference between static controller and non static controller in play framework with Java (播放2.1.3)最小化模型中的代码。 静态方法的泛型 - (Play 2.1.3) minimize the code in models. Generics for static methods Play Framework - 使用Promise.failure的方法的接口(异常) - Play Framework - Interfaces for methods that use Promise.failure(exception)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM