第一个实例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}"/>
知识离开了脑子,就只是一堆文字

浙公网安备 33010602011771号