Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 获取要附加区域设置的Thymeleaf@{}表达式_Spring_Spring Mvc_Thymeleaf - Fatal编程技术网

Spring 获取要附加区域设置的Thymeleaf@{}表达式

Spring 获取要附加区域设置的Thymeleaf@{}表达式,spring,spring-mvc,thymeleaf,Spring,Spring Mvc,Thymeleaf,我的上下文路径是/,我将直接添加区域设置作为路径的一部分:/de/index.html 现在我面临的问题是th:href=“@{/login.html}”将解析为/login.html,而不是/de/login.html 我已经试过制作一个过滤器和一个拦截器,就像他们在这里做的那样: 但它仍然不会在上下文路径后追加de/ 编写我自己的方言和属性处理器将是一个解决方案,但没有更好的解决方案吗?为什么不公开区域设置的模型属性(例如curLocale)并重新定义所有URL th:href="@{/${

我的上下文路径是
/
,我将直接添加区域设置作为路径的一部分:
/de/index.html

现在我面临的问题是
th:href=“@{/login.html}”
将解析为
/login.html
,而不是
/de/login.html

我已经试过制作一个过滤器和一个拦截器,就像他们在这里做的那样:

但它仍然不会在上下文路径后追加
de/


编写我自己的方言和属性处理器将是一个解决方案,但没有更好的解决方案吗?

为什么不公开区域设置的模型属性(例如curLocale)并重新定义所有URL

th:href="@{/${curLocale}/login.html}"
thymileaf允许url表达式本身中的其他表达式。
语言环境信息可以作为方法参数或通过调用RequestContext.getLocale()轻松访问。

经过数小时的步骤调试,我自己找到了一个干净而好的解决方案:

是的,在我们的项目中,我们有类似的要求,我们实现了方言和处理器,但在我看来,这不是一个好的解决方案,这似乎是不编写我自己的方言的唯一方法。但我不想在每个链接中都使用区域设置。所以这不是我的选择。