如何获得百里香的内容路径? [英] How to get content path in thymeleaf?

查看:53
本文介绍了如何获得百里香的内容路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用springboot 1.5.10,eclipse IDE和Thymeleaf的项目.

I have a project using springboot 1.5.10, eclipse IDE and Thymeleaf.

在几页中,我在jquery中都有这样的重定向:

In several pages I have redirections like this in jquery:

例如:在选择选项中

$('#month').on('change', function() {

    window.location = "/dashboard/operation/month/" + month;
})

例如:按钮中

$('#bFind').click(function() {
  var newUrl = "/dashboard/operation/month/";
  newUrl += month;
  $('a').attr('href', newUrl);
});

在我的控制器中定义的两种重定向都很好用.

Both redirect works great defined in my Controller.

网址为: http://localhost:8080/dashboard/operation/month/01

但是问题是当我创建一个战争项目以将其部署到apache tomcat 9.0.6中时,我必须给出要部署的名称.

But the problem is when I create a war project to deploy it in my apache tomcat 9.0.6 I have to give a name to deploy.

部署完后,URL为: http://localhost:8080/mywebapp/dashboard/operation/month/01

Once you have deployed the url is: http://localhost:8080/mywebapp/dashboard/operation/month/01

它破坏了东西...

mywebapp 可能是另一个名称.

所以我一直在寻找添加上下文路径:

So I have been looking for add context path:

我发现的主要信息是:

但是当我将其添加到may header.html文件中时,我总是无法定义

But when I add this to may header.html file I get always undefined

<meta name="ctx" th:content="${#httpServletRequest.getContextPath()}" />

也许还有另一种方法可以正确地添加上下文路径.

Maybe is there is another way to do this and add the context path correctly.

有什么建议吗?

谢谢

推荐答案

https://www.thymeleaf.org/doc/articles/standardurlsyntax.html

也许试试看:

<meta name="ctx" th:content="@{/}" />

如果上下文是localhost:8080,它将输出

If the context is localhost:8080, it will output

<meta name="ctx" content="/" />

但是,如果您的上下文是localhost:8080/mywebapp,它将输出

But if your context is localhost:8080/mywebapp it will output

<meta name="ctx" content="/mywebapp/" />

这篇关于如何获得百里香的内容路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆