Sling Model的作用
Entirely annotation driven. “Pure” POJOs.
纯注解驱动
Use standard annotations where possible.
尽可能的使用标准注释
Pluggable
可插入的
OOTB, support resource properties (via ValueMap), SlingBindings, OSGi services, request attributes.
支持资源属性(通过ValueMap)、SlingBindings、OSGi服务和请求属性
Adapt multiple objects - minimal required Resource and SlingHttpServletRequest
适应多个对象-最小所需Resource和SlingHttpServletRequest
Client doesn’t know/care that these objects are different than any other adapter factory
客户端不知道/不关心这些对象是否与其他适配器工厂不同
Support both classes and interfaces.
支持类和接口。
Work with existing Sling infrastructure (i.e. not require changes to other bundles).
使用现有Sling基础设施(即不需要更改其他捆绑包)。
基本用法
在最简单的情况下,用@Model和可适应的类对类进行注释。需要注入的字段用@Inject注释:
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
private String propertyN