千家信息网

Sling model的作用是什么

发表于:2025-01-31 作者:千家信息网编辑
千家信息网最后更新 2025年01月31日,本篇内容介绍了"Sling model的作用是什么"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!In
千家信息网最后更新 2025年01月31日Sling model的作用是什么

本篇内容介绍了"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 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的作用是什么"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0