本篇内容介绍了“Sling model的作用是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
Internal object:
import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.injectorspecific.SlingObject; @Model( adaptables = {Resource.class}) public class AbstractModelResource { @SlingObject ResourceResolver resolver; @SlingObject Resource resource; }
real fields:
@Model(adaptables=Resource.class,defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) public class JobDetailModel extends AbstractModel{ @OSGiService JobTriggerService jobTriggerService; private JobEntity job; private String appUrl; private String postingDate; private String postingDateFormat; @Inject @Optional @Named("subTitle") @Default(values="") private String subTitle; @Inject @Optional @Named("qualifications") @Default(values="") private String qualifications; @Inject @Optional @Named("jobID") @Default(values="") private String jobID; @Inject @Optional @Named("jobFunction") @Default(values="") private String jobFunction; @Inject @Optional @Named("postingDateLabel") @Default(values="") private String postingDateLabel; @Inject @Optional @Named("applyBtn") @Default(values="") private String applyBtn; @Inject @Optional @Named("scheduleLabel") @Default(values="") private String scheduleLabel; @Inject @Optional @Named("jobDetailsText") @Default(values="") private String jobDetailsText; @Inject @Optional @Named("relJobsText") @Default(values="") private String relJobsText; @Inject @Optional @Named("Job") private JobModel jobModel; @PostConstruct protected void init() { } }
Job Model:
import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Default; import org.apache.sling.models.annotations.Model; import org.apache.sling.models.annotations.Optional; import javax.inject.Inject; import javax.inject.Named; import java.util.List; @Model(adaptables = Resource.class) public class JobModel { @Inject @Optional@Named("BrandName") @Default(values="") private String BrandName; @Inject @Optional @Named("PrimaryLocation") PrimaryLocation primaryLocation; @Inject @Optional @Named("Postings") List<PostingModel> postings; @Inject @Optional @Named("JobField") JobField JobField; @Model(adaptables = Resource.class) public static class PrimaryLocation{ @Inject @Optional @Named("Country") @Default(values="") String Country; @Inject @Optional @Named("State") @Default(values="") String State; } }
for request:
@Model(
adaptables = {Resource.class, SlingHttpServletRequest.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public abstract class AbstractModel extends AbstractModelResource{
@SlingObject
ResourceResolver resolver;
@Inject
@Via("resource")
Resource resource;
@Inject
@Via("request")
SlingHttpServletRequest request;
@OSGiService
}
“Sling model的作用是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。