HTML templates in spring boot similar to play fram

2019-07-23 03:20发布

问题:

I have worked with PlayFramework for Scala. Now I am starting with Spring (Spring Boot) for the first time. Is their any way to make HTML templates similar to Play framework. e.g. passing HTML content into a main(main.scala.html) HTML file.

回答1:

Spring framework does not force you to use any particular view technology. You can use anything that can be integrated. The topic is covered in the documentation where you can read about the details on popular choices. However, the most popular is Thymeleaf, which used to be a part of Spring MVC before separation into an independent project. You can find a clear example on how to use it with Spring Boot in the getting started guide.

The templates in Play framework created using Twirl framework are converted into Scala code. You simply pass the data model via template parameter list, just like you do with any method.

In Spring framework you put all date that you want to expose to your view in a so-called model map, which is a simple key-value storage. In the view technology you refer the values using corresponding keys.