Grails Feeds Plugin 使用經(jīng)驗小結(jié)
先采用標(biāo)準(zhǔn)使用方法: 1
class YourController {
2
def feed = {
3
render(feedType:"rss", feedVersion:"2.0") {
4
title = "My test feed"
5
link = "http://your.test.server/yourController/feed"
6
description = "The funky Grails news feed"
7
Article.list().each() {article ->
8
entry(article.title) {
9
link = "http://your.test.server/article/${article.id}"
10
article.content // return the content
11
}
12
}
13
}
14
}
15
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

如果在一個grails應(yīng)用只有一個feed實例,沒發(fā)現(xiàn)什么問題,覺得這個插件還挺不錯的。因為JavaRead要提供多個feed,后來才發(fā)現(xiàn),但是一旦超過一個,那么只有一個能用。其他的直接拋出grails異常信息:
1
No such property: title for class: ArticleController
2
Caused by: groovy.lang.MissingPropertyException: No such property: title for class: ArticleController

2

最后翻了一下插件的代碼,改了一下迂回解決了這個問題。
1
def feed = {
2
def builder = new feedsplugin.FeedBuilder()
3
builder.feed {
4
title = "JavaRead熱文"
5
link = "http://www.javaread.com/article/list"
6
description = "最新鮮的Java資訊"
7
Article.listOrderById(max:20, order:"desc") .each() { article ->
8
entry {
9
title = article.title
10
link = "http://www.javaread.com/article/show/${article.id}"
11
article.overview
12
}
13
}
14
}
15
def feed = builder.makeFeed('rss')
16
StringWriter writer = new StringWriter()
17
SyndFeedOutput output = new SyndFeedOutput()
18
output.output(feed,writer)
19
writer.close()
20
render(writer.toString())
21
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

本文作者:javaread.com
posted on 2008-07-24 16:35 javaread.com 閱讀(1008) 評論(0) 編輯 收藏