小编Ale*_*ver的帖子

Thymeleaf:语言选择器的 Switch 语句

我正在为 Spring Boot 项目使用 Thymeleaf 实现语言选择器,但我无法在 case 语句中使用变量 ${#ctx.locale}。它始终采用默认值(“*”)。

<li class="nav-item dropdown">
<a class="nav dropdown-toggle"
   id="languages" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">

        <i class="material-icons">language</i>

        <div th:switch="${#ctx.locale}">
            <p th:case="en">English</p>
            <p th:case="es">Español</p>
            <p th:case="ca">Català</p>
            <p th:case="*">English</p>
        </div>
</a>
<div class="dropdown-menu" aria-labelledby="languages">
    <a class="dropdown-item" th:href="@{?lang=en}">English</a>
    <a class="dropdown-item" th:href="@{?lang=es}">Español</a>
    <a class="dropdown-item" th:href="@{?lang=ca}">Català</a>
</div>
Run Code Online (Sandbox Code Playgroud)

事实上,我只需要语言名称。谢谢你。

thymeleaf spring-boot

4
推荐指数
1
解决办法
6950
查看次数

将日期插入PostgreSQL:列和来自

我无法date在PostgreSQL 9.6表中插入.

这是INSERT查询:

INSERT INTO rates (idproperty, from, to, price)
VALUES (1, '2017-03-14', '2017-04-30', 130);
Run Code Online (Sandbox Code Playgroud)

这就是结果:

ERROR:  syntax error at or near "from"
LINE 1: INSERT INTO rates (idproperty, from, to, price)
Run Code Online (Sandbox Code Playgroud)

fromto使用数据类型定义date.

谢谢

database postgresql

3
推荐指数
2
解决办法
2万
查看次数

使用打包在.jar中的Thymeleaf的Spring Boot错误解析模板

我有一个使用Thymeleaf作为模板解析器的Spring Boot应用程序,从NetBeans调试时可以正常工作,但是在运行其.jar时出现此错误:

错误解析模板“ / theme / property”,模板可能不存在,或者任何已配置的模板解析器都无法访问该模板

在SpringBootServletInitializer的扩展名下,该应用程序设置为使用@SpringBootApplication批注进行自动配置。我尚未在属性文件中设置任何contextPath。我正在使用Thymeleaf 2.1.6和Spring 4版本。这个罐子是用Maven生成的。

做一些研究,我发现在某些控制器中我传递了一个双斜杠,我已经解决了这个问题,但是大多数页面仍然无法正常工作。

该控制器的工作原理是:

@GetMapping("/{idweb}")
String frontEndHome(@PathVariable("idweb")Integer idweb, Model model){
...
return "theme/home";
Run Code Online (Sandbox Code Playgroud)

将return语句设置为return“ / theme / home”; 不起作用。我猜是因为模板解析器收到了双斜杠(//)。

此其他控制器引发错误:

@GetMapping("/{idweb}/property")
String frontEndProperty(@PathVariable("idweb") Integer idweb, @RequestParam(value = "idproperty", required = false) Integer idproperty, Model model) throws Exception {
...
return "theme/property";
Run Code Online (Sandbox Code Playgroud)

索引控制器也可以正常工作:

@GetMapping("/")
public String index(Model model){
   ...
   return "index";
}
Run Code Online (Sandbox Code Playgroud)

那是我的应用程序入门类:

@SpringBootApplication
public class RentalWebsApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder  application) {
       return application.sources(RentalWebsApplication.class);
    }

    public static void …
Run Code Online (Sandbox Code Playgroud)

spring-mvc thymeleaf spring-boot

2
推荐指数
1
解决办法
6480
查看次数