playframework - Play Framework 2 中的 Getter/Setter 翻译

标签 playframework playframework-2.0 playframework-1.x playframework-2.1

Play Framework 1 有一个很棒的功能,直接为模型属性赋值会在运行时自动转换为函数调用。 Here are the docs .例如

model.fullname = "John Smith";

将在引擎盖下自动转换为:
model.setFullname("John Smith");

Play Framework 2 中是否存在相同的功能?

它在任何地方都有记录吗?

这是一个 sample java project我试图让该功能在 Play 2.1.1 中工作。它表明正在创建 getter 和 setter,但没有重写客户端字节代码来调用生成的 getter 和 setter。

最佳答案

这是本书的摘录:Play For Java

Play uses a cool trick called ‘byte code enhancement’ to add getters and setters right after your original code is compiled, and then silently rewrites all your client byte code to use the generated getters and setters. However, if you change from field access to getter/setters, or the other way around, you'll find your code no longer compiles. This is because the bytecode enhancement takes place after your class is compiled, which means it has to actually compile first.



您是否将字段访问权限更改为 getter/setter,或者相反?

关于playframework - Play Framework 2 中的 Getter/Setter 翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16650841/

相关文章:

java - Play Framework 2.0 表单助手 : from select to List<T>

java - 如何在 java play 2.5 中创建带有内存数据库的虚假应用程序?

java - 使用 Spring、Play Framework、Struts 构建的网站示例

java - 如何将表单字段绑定(bind)到 Play 2 Framework 中的对象

java - 在 Controller 外部获取 JPA 事务 - Play Framework

java - 如何使用 AJAX 查询动态填充 Google Chart,获取 DOM 异常 8

forms - 玩2.4 : Form: could not find implicit value for parameter messages: play. api.i18n.Messages

forms - Scala Play 表单验证 : different forms for one case class - is it possible?

playframework - 将参数传递给 main.scala.html

playframework - 如果 Url 在 Play Framework 中无效,则重定向到错误页面。 1.25?