> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/thymeleaf/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/thymeleaf/i.-using-thymeleaf/4-standard-expression-syntax/4.15-data-conversion-and-formatting.md).

# 4.15 数据转换/格式化

Thymeleaf为变量（`${...}`）和选择（`*{...}`）表达式定义了一种双大括号语法。这种语法允许我们用配置好的转换服务来应用数据转换。

这种语法大致上像这样：

```markup
<td th:text="${{user.lastAccessDate}}">...</td>
```

注意到这里的大括号了嘛？`${{...}}`。那会通知Thymeleaf把表达式`user.lastAccessDate`的结果传递给转换服务，并请求它在写出结果之前执行**格式化操作**（转换为`String`）。

假设`user.lastAccessDate`是`java.util.Calendar`类型，如果一个转换服务（`IStandardConversionService`的实现）已经注册，而且包含了有效的`Calendar -> String`转换，那么此转换将会被应用。

`IStandardConversionService`的默认实现（`StandardConversionService`类）仅仅执行任何对象上的`.toString()`方法。关于如何注册一个自定义的转换服务实现，请查看[与配置有关的更多内容](http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#more-on-configuration)章节。

```
官方的thymeleaf-spring3和thymeleaf-spring4整合包用Spring自己的转换服务基础设施，
透明地集成了Thymeleaf的转换服务机制。
这样，在Spring配置里声明的转换服务和格式化器将会自动对`${{...}}`和`*{{...}}`表达式可用。
```
