ArchiveArticleController.java 1.1 KB
Newer Older
U
u014427391 已提交
1 2 3 4 5 6 7 8 9 10
package net.myblog.web.controller;

import net.myblog.entity.Article;
import net.myblog.service.ArticleService;
import net.myblog.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

11 12 13 14 15 16 17
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 *  文章归档控制类
 */
U
u014427391 已提交
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
@Controller
public class ArchiveArticleController extends BaseController{

	@Autowired ArticleService articleService;
	
	@RequestMapping("/getArchiveArticles")
	public ModelAndView getArticleByMonth(HttpServletRequest request){
		String yearMonthString = request.getParameter("yearmonth");
		ModelAndView mv = this.getModelAndView();
		
		Date yearmonth = DateUtils.parse("yyyy-MM", yearMonthString);
		
		List<Article> articles = articleService.findArticleByMonth(yearmonth);

		mv.addObject("articles", articles);
		mv.setViewName("myblog/article/archive_articles");
		return mv;
	}
	
	
}