小编ada*_*een的帖子

在Thymeleaf格式化日期

我是Java/Spring/Thymeleaf的新手,所以请关注我目前的理解水平.我确实审查了这个类似的问题,但无法解决我的问题.

我想要一个简化的日期而不是长日期格式.

// DateTimeFormat annotation on the method that's calling the DB to get date.
@DateTimeFormat(pattern="dd-MMM-YYYY")
public Date getReleaseDate() {
    return releaseDate;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<table>
    <tr th:each="sprint : ${sprints}">
        <td th:text="${sprint.name}"></td>
        <td th:text="${sprint.releaseDate}"></td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

电流输出

sprint1 2016-10-04 14:10:42.183
Run Code Online (Sandbox Code Playgroud)

java datetime-format thymeleaf spring-boot

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

错误:尝试在空上下文对象上调用方法"format"

Spring-boot v1.4.1
Java v1.8
Thymeleaf v2.1.5.

我视图中的以下代码行:

<td th:each = "sprint : ${sprints}" th:text = "${sprint.releaseDate} ? ${#temporals.format(sprint.releaseDate, 'MMM/dd/yyyy')}"></td>
Run Code Online (Sandbox Code Playgroud)

我有基于SO问题SpringBoot Thymeleaf Ordinal Numbers的语法产生错误:

org.springframework.expression.spel.SpelEvaluationException:EL1011E:(pos 11):方法调用:尝试在空上下文对象上调用方法格式(java.time.LocalDate,java.lang.String)

但是,如果我在没有Thymeleaf格式的情况下运行这行代码,它将工作并以默认格式呈现LocalDate对象表("2016-05-25").

问题:为什么我收到'空上下文对象'错误,这是什么意思?我如何编辑以获得我想要的格式?

java spring date-formatting thymeleaf spring-boot

6
推荐指数
2
解决办法
7532
查看次数

javascript排序方法没有在数组[1]上运行

var test = ['hello', 'Hello']
var arg1 = test[0].split('').sort().join('').toLowerCase();  // ehllo
var arg2 = test[1].split('').sort().join('').toLowerCase();  // hello
Run Code Online (Sandbox Code Playgroud)

有人能够解释为什么sort方法似乎对测试数组的第二个元素没有影响吗?

javascript arrays sorting methods

0
推荐指数
1
解决办法
81
查看次数