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";
}
@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";
}
相关文章推荐
- (原创)js,ajax与springboot之间的两种传参方式
- 3.Spring Boot + Security初步使用(覆盖配置的两种方式 配置类和XML注入以自定义页面为例)
- springboot 常用两种图形形式(thymeleaf模板,jsp页面)
- Spring Boot---(16)Spring Boot使用Thymeleaf开发web页面
- SpringBoot thymeleaf模板页面没提示,SpringBoot thymeleaf模板插件安装
- JavaWeb日记——Springboot 热部署的两种方式
- Spring Boot 实现热部署两种方式
- 基于springboot搭建dubbo框架(注解和xml配置两种方式)
- SpringBoot建立数据库连接JdbcTemplate和Mybatis两种方式
- 访问不存在的Thymeleaf 资源时使页面转向 404,而不是500 (Spring Boot)
- 微服务,微架构[十一]springboot模板页面thymeleaf
- spring boot thymeleaf常用方式
- spring boot返回Josn的两种方式
- 基于Maven的SpringBoot项目实现热部署的两种方式
- Springboot 热部署的两种方式
- springboot 使用 thymeleaf 模板引擎。在页面写隐藏域接收后台的值。在页面进行对话框提示。
- spring-boot自动部署的两种方式
- springboot如何使用thymeleaf模板访问html页面
- Spring-boot中读取config配置文件的两种方式
- Spring Boot获取前端页面参数的几种方式总结