1.利用ModelAndView对象向页面传参
@RequestMapping("/index/{p}.html")
public ModelAndView index(@PathVariable int p,String keyword){
ModelAndView view = new ModelAndView();
view.setViewName("index");
//因为用了spring boot缓存,sb是用返回值做缓存,所以service再次返回了pageQuery以缓存查询结果
List<Topic> findTopicsByPage = topicService.findTopicsByPage(p,Const.TOPIC_PAGE_SIZE);
view.addObject("topicPage", findTopicsByPage);
view.addObject("pagename", "首页综合");
return view;
}
2.利用model对象向页面传参
@RequestMapping("/index/{p}.html")
public String index(Model model){
//因为用了spring boot缓存,sb是用返回值做缓存,所以service再次返回了pageQuery以缓存查询结果
List<Topic> findTopicsByPage = topicService.findTopicsByPage(1,Const.TOPIC_PAGE_SIZE);
model.addAttribute("topicPage", findTopicsByPage);
model.addAttribute("pagename", "首页综合");
return "index";
}