从FreeMarker模板访问Java嵌套类

时间:2016-05-10 17:12:18

标签: java freemarker

public class MyModel {

  private final com.google.gson.Gson gson = new Gson();
  private final SomeData someData = new SomeData();

  private class SomeData extends JsonModel() {
    String text = "text";
  }

  private class JsonModel() {
    public String toJson() {
      return gson.toJson(this);
    }
  }

  public SomeData getSomeData() {
    return someData;
  }
}

假设MyModel在FTL中可以myModel访问,为什么myModel.someData.toJsonmyModel.getSomeData().toJson()会因The following has evaluated to null or missing: myModel.someData.toJsonThe following has evaluated to null or missing: myModel.getSomeData().toJson()而失败?

1 个答案:

答案 0 :(得分:2)

JsonModel必须是公开的,否则其成员不会被曝光。