第一个实例Sling Model+HTL

  • @Named可以绑定数据
  • 若不绑定用protected Date trainingdate;也是可以的
    下面用getTrainingDate()仍然是可以取到的
  • 奇葩的是:即便我用的是trainingdate在HTL中写hello.trainingDate也能取到

实则不用@ValueMapValue,@Inject就能注入然后取到值了

package com.xxx.core.models;

@Model(adaptables = Resource.class)
public class GenericPageModel {

    @ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL)
    @Named("trainingdate")//节点中为./trainingdate
    protected Date trainingDate;

    public String getTrainingDate(){
        return trainingDate.toString();
    }

}

HTL:
    <meta data-sly-use.hello="com.xxx.core.models.GenericPageModel" name="trainingdate" content="${hello.trainingDate}"/>
posted @ 2021-01-13 14:24  lwxx  阅读(203)  评论(0)    收藏  举报