RSS 和 Atom
AbstractAtomFeedView
和AbstractRssFeedView
都继承自AbstractFeedView
基类,分别用于提供Atom和RSS Feed视图。它们基于ROME项目,位于org.springframework.web.servlet.view.feed
包中。
AbstractAtomFeedView
要求您实现buildFeedEntries()
方法,并可以选择覆盖buildFeedMetadata()
方法(默认实现为空)。以下示例显示了如何做到这一点
-
Java
-
Kotlin
public class SampleContentAtomView extends AbstractAtomFeedView {
@Override
protected void buildFeedMetadata(Map<String, Object> model,
Feed feed, HttpServletRequest request) {
// implementation omitted
}
@Override
protected List<Entry> buildFeedEntries(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// implementation omitted
}
}
class SampleContentAtomView : AbstractAtomFeedView() {
override fun buildFeedMetadata(model: Map<String, Any>,
feed: Feed, request: HttpServletRequest) {
// implementation omitted
}
override fun buildFeedEntries(model: Map<String, Any>,
request: HttpServletRequest, response: HttpServletResponse): List<Entry> {
// implementation omitted
}
}
实现AbstractRssFeedView
也需要类似的要求,如下例所示
-
Java
-
Kotlin
public class SampleContentRssView extends AbstractRssFeedView {
@Override
protected void buildFeedMetadata(Map<String, Object> model,
Channel feed, HttpServletRequest request) {
// implementation omitted
}
@Override
protected List<Item> buildFeedItems(Map<String, Object> model,
HttpServletRequest request, HttpServletResponse response) throws Exception {
// implementation omitted
}
}
class SampleContentRssView : AbstractRssFeedView() {
override fun buildFeedMetadata(model: Map<String, Any>,
feed: Channel, request: HttpServletRequest) {
// implementation omitted
}
override fun buildFeedItems(model: Map<String, Any>,
request: HttpServletRequest, response: HttpServletResponse): List<Item> {
// implementation omitted
}
}
buildFeedItems()
和buildFeedEntries()
方法传入HTTP请求,以防您需要访问Locale。HTTP响应仅用于设置cookie或其他HTTP标头。方法返回后,馈送会自动写入响应对象。
有关创建Atom视图的示例,请参见Alef Arendsen的Spring团队博客条目。