spring boot与thymeleaf页面传参两种方式

来源:互联网 发布:oracle数据库有可视化 编辑:程序博客网 时间:2024/06/05 12:43

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";

}


原创粉丝点击