Thymeleaf mit Spring
Hinweis
e .jar files ( thymeleaf-spring3-{version}.jar and thymeleaf-spring4-{version}.jar ) and need to be added to your classpath in order to use Thymeleaf’s Spring integrations in your application.
Beispielprojekt
Ein Beispielprojekt für die Thymeleaf und Spring-Kombination befindet sich auf GitHub.
Unterschiede zum Thymeleaf (Standalone)
Use Spring Expression Language (Spring EL) instead of OGNL in your templates. Note that all utility objects like #lists are available in Spring EL expressions just as they were in OGNL expressions in the Standard Dialect.
Der SpringStandard Dialekt
Besides all the features already present in the Standard Dialect – and therefore inherited –, the SpringStandard Dialect introduces the following specific features:
- Use Spring Expression Language (Spring EL) as a variable expression language, instead of OGNL. Consequently, all
${...}
and*{...}
expressions will be evaluated by Spring’s Expression Language engine.- Access any beans in your application context using SpringEL’s syntax:
${@myBean.doSomething()}
- New attributes for form processing:
th:field
,th:errors
andth:errorclass
, besides a new implementation ofth:object
that allows it to be used for form command selection.- An expression object and method,
#themes.code(...)
, which is equivalent to thespring:theme
JSP custom tag.- An expression object and method,
#mvc.uri(...)
, which is equivalent to thespring:mvcUrl(...)
JSP custom function (only in Spring 4.1+).- New DTDs for validation, including these new attributes, as well as new corresponding DOCTYPE translation rules.
Begriffe
Views
Views are in charge of rendering the actual HTML interface
View Resolvers
ViewResolvers are the objects in charge of obtaining View objects for a specific operation and locale. Typically, controllers ask ViewResolvers to forward to a view with a specific name