Maven project development steps (4) Based on the springboot

We talk about this springboot integrated template engine. Project in general is going to take a page to display the data. springboot where you can integrate freemarker templates can also integrate thymeleaf template.

[Template] integration freemarker steps:

1, open pom.xml file, add the following dependence: Also added to the <dependencies> tag.

              <dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-freemarker</artifactId>

</dependency>

2, in src / main / resources in a new folder, this folder for placing freemarker page template (page file suffix is ​​ftl). Custom folder name, I am here defined as templates.

image.png

3, application.properties open file, add the following configuration: FIG.


spring.freemarker.template-loader-path=classpath:/templates

# Turn off caching, real-time refresh, on-line production environment needs to true

spring.freemarker.cache=false

spring.freemarker.charset=UTF-8

spring.freemarker.check-template-location=true

spring.freemarker.content-type=text/html

spring.freemarker.expose-request-attributes=true

spring.freemarker.expose-session-attributes=true

spring.freemarker.request-context-attribute=request

spring.freemarker.suffix=.ftl


image.png

4, then we create a new folder ftl file templates file, as ftl file content and wording html file.

image.png

code show as below:

image.png

We add data in the page:

image.png

5, add the following method in the controller class: the process jumps are test.ftl the page and transfer the data out.

image.png

6, open the browser, type HTTP: // localhost: 8080 / the Test / toftl , press Enter to see the effect:

image.png

Guess you like

Origin blog.51cto.com/13082457/2431481