问题描述
我是Apache Sling,CQ5等的新手。
I am new to Apache Sling, CQ5, etc.
在我们的代码库中,我们有一个类似于以下内容的代码段:
In our codebase, we have a code snippet similar to this:
void perform(SlingHttpServletRequest request, SlingHttpServletResponse response) {
ResourceResolver resourceResolver = request.getResourceResolver();
Session session = resourceResolver.adaptTo(Session.class);
PageManager pageManager = resourceResolver.adaptTo(PageManager.class);
}
adapTo
在做什么在这里?
还有可用的良好文档/用户手册,我可以阅读以开始使用Sling,CQ5等吗?
Also is there a good documentation/user manual available I can read to get started using Sling, CQ5, etc.?
推荐答案
在许多吊索对象中找到的AdaptTo()方法允许转换对象。
Sling可以决定添加resolver.getSession()方法,但这并不是很灵活。 AdaptTo的好处在于它是动态的。您可以创建适配器以在不同类型之间进行转换(它们是OSGi服务)。 Sling和CQ5还包括,默认。 sling Wiki上有一些有关的文档。
The adaptTo() method found in many sling objects allows to "transform" objects. Sling could have decided to add a resolver.getSession() method, but that wouldn't have been very flexible. The nice thing about adaptTo is that is it dynamic. you can create adapters to transform between different types (they are OSGi services). Sling and CQ5 also include bunch of adapters by default. The sling Wiki has some docs about adapters.
关于如何开始使用Sling和CQ5,是一个很好的起点
About how to start with Sling and CQ5, the sling site is a good place to start
这篇关于Apache Sling中resourceResolver.adaptTo(Session.class)的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!