A Java class located in the OSGi bundle is annotated with @Model and the adaptable class. The data members (Fields) use the @Inject annotation. Consider the following Java class.
package org.kalyan.poc.sling.models;
import javax.inject.Inject;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.Model;
@Model(adaptables = Resource.class)
public class UserInfo {
@Inject
private String firstName;
@Inject
private String lastName;
@Inject
private String technology;
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getTechnology() {
return technology;
}
}
As you can see the @Model annotation is used. Likewise, each data member in the UserInfo class is annotated using @Inject. For more information about Sling Models, see Sling Models.
This article walks you through creating an AEM application that uses Sling Models. To read this development article, click https://helpx.adobe.com/experience-manager/using/sling_models.html,
Join the Adobe Experience Cloud Community
Join the Adobe Experience Cloud Community by clicking this banner
I (Scott Macdonald) am a Senior Digital Marketing Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If you would like to see more CQ or other Adobe Digital Marketing end to end articles like this, then leave a comment and let me know what content you would like to see.
Twitter: Follow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.
YouTube: Subscribe to the AEM Community Channel.
Twitter: Follow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.