What is the function of Sling model?
This article introduces the relevant knowledge of "what is the role of Sling model". In the operation of actual cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
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
}
This is the end of the content of "what is the function of Sling model". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!