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/