日期:2014-05-17 浏览次数:20883 次
<action name="article_public" class="articlePublicAction">
<result name="ArticlePublicPage">/article_public.jsp</result>
<result name="Self" type="redirectAction">article_public</result>
</action>
public String execute()
{
articles=articleService.listPublish();
//查询所有文章信息,显示文章信息列表
return "ArticlePublicPage";
}
public String delete()
{
articleService.deleteArticle(articleid);
//删除id=articleid的文章后跳转回文章列表
return "Self";
}
public List<ArticleInfo> listPublish() {
//将检索到文章的信息进行封装
List<ArticleInfo> result = new ArrayList<ArticleInfo>();
List<Map> list = articleDao.listPublish();
for (Map item : list) {
ArticleInfo ai = new ArticleInfo();
ai.setCategory((String) item.get("category"));
ai.setCreateTime((Date) item.get("createTime"));
ai.setId((Integer) item.get("id"));
ai.setTags((String) item.get("tags"));
ai.setTitle((String) item.get("title"));
ai.setType((Integer) item.get("type"));
result.add(ai);
}
return result;
}
public void deleteArticle(int id) {
Article article = articleDao.getArticle(id);
if (article != null) {
articleDao.deleteArticle(article);
}
}
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<Map> listPublish() {
//这里不直接检索Article对象是为了去掉对文章正文的检索而降低检索效率
return this.getSession(true).createQuery("select new Map(a.id as id,a.type as type,a.title as title,a.tags as tags,a.category.name as category,a.createTime as createTime) from Article a where a.status=1 order by a.createTime desc").list();
}
public Article getArticle(int id) {
return this.getHibernateTemplate().get(Article.class, id);
}
public void deleteArticle(Article article) {