【问题标题】:Playframework: Is it possible to pass parameters to a Model's getter in the template?Playframework:是否可以在模板中将参数传递给模型的 getter?
【发布时间】:2013-07-20 14:41:32
【问题描述】:

我不知道怎么形容,所以问题标题可能没有多大意义。

说,我有一个名为User的类:

class User {
    public String name;

    public String getName(){
        return this.name;
    }

    public String getName(long level){
        // Calculate the name with level.
        return name;
    }
}

我知道我可以在模板中使用${user.name} 来调用getName() 函数,但是如果我想通过level 在模板中调用getName(long level) 怎么办?

有没有类似${user.name(123)}的替代方案

有可能吗?

【问题讨论】:

    标签: groovy playframework playframework-1.x


    【解决方案1】:

    你只需要

    ${user.getName(123)}
    

    【讨论】:

      猜你喜欢
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-03
      • 1970-01-01
      相关资源
      最近更新 更多