加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – Spring百里叶的页眉和页脚动态包括

发布时间:2020-12-15 01:26:19 所属栏目:大数据 来源:网络整理
导读:我最近在春天开始使用百里香模板引擎.我想要实现的是 如果我的控制器就是这个 @RequestMapping(value="/",method=RequestMethod.GET)public String index() { return "homePage";} 然后我想在homePage.html中编写HTML代码而没有像head,title,body等完整的HTM

我最近在春天开始使用百里香模板引擎.我想要实现的是 – 如果我的控制器就是这个

@RequestMapping(value="/",method=RequestMethod.GET)
public String index() {
    return "homePage";
}

然后我想在homePage.html中编写HTML代码而没有像head,title,body等完整的HTML定义.

不想在homePage.html这样写.

我更倾向于将头部分作为标题片段,来自控制器和页脚的内容来自页脚片段.

所以总的来说 – 我怎么能做到这一点:

/fragment/header.html

/home.html

(这个投掷错误)

/fragment/footer.html

  

注意:我已经看过这些例子了

> http://www.thymeleaf.org/doc/articles/layouts.html
> https://looksok.wordpress.com/2014/06/28/spring-website-layouts-ssi-with-thymeleaf-templates/
> http://blog.codeleak.pl/2013/11/thymeleaf-template-layouts-in-spring.html

最佳答案
我解决了这个问题:

Controller指向index.html并给出“内容页面”的属性

@RequestMapping(value={"/"})
   public String root(Locale locale,ModelMap model) {
   model.addAttribute("content","helloWorldView");     
   return "index";
}

这是我的index.html:

所以我有一个带页眉和页脚的文件夹片段:

片段/了header.html

片段/ footer.html

在我的文件夹视图中,我获得了包含内容的所有视图
意见/ helloWorldView.html:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读