您的位置:首页 > 编程语言 > Java开发

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

2017-12-06 11:17 429 查看
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";

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  springboot thymeleaf