Springboot Front End Template

Source: Internet
Author: User

Springboot supports Thymeleaf, Freemarker, JSP, but the official does not recommend using JSP, because some features will be limited, here is a description of Thymeleaf and Freemarker.
One, thymeleaf template

The front-end interface of the Thymeleaf template is an. html format file that can be viewed directly using a browser to facilitate the debugging of styles. 1. Pom Dependencies Add

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId> Spring-boot-starter-thymeleaf</artifactid>
        </dependency>

Viewing the Maven affinity tree through MVN dependency:tree, you find that Thymeleaf automatically relies on importing Web packages, so you no longer have to import Web packages. 2. Application Property Configuration

The default configuration for viewing official documents is described below:

It must be noted here that the development of the time to turn off the template cache, or modify the interface file can not be displayed in real time. To turn off the template cache in the Application.properties file:

Spring.thymeleaf.cache=false

After the cache is turned off, the HTML file is modified so that it can be directly ctrl+f9 compiled to display the latest modifications. 3, the writing interface

My interface hello.html path is: templates/template/hello.html, code:

<! DOCTYPE html>
4, the preparation of controller
Package com.example.demo.template;

Import Org.springframework.stereotype.Controller;
Import Org.springframework.ui.Model;
Import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping ("/html") public
class Htmlcontroller {

    @RequestMapping ("/hello")
    Public String Hello (model model) {
        model.addattribute (' name ', ' World ');

        return "Template/hello";
    }

Run the access as follows:

thymeleaf Specific Use reference

http://blog.csdn.net/z719725611/article/details/53908294 II, freemarker template 1, pom dependencies add

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId> Spring-boot-starter-freemarker</artifactid>
        </dependency>

Note: Allow Thymeleaf and freemarker to exist at the same time 2, Application property configuration

The default configuration for viewing official documents is described below:

application.properties files need not be configured, use the default configuration 3, write the interface

My interface HELLO.FTL path is: TEMPLATES/FTL/HELLO.FTL, code:

<! DOCTYPE html>
4, the preparation of controller
Package com.example.demo.template;

Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;

Import Java.util.Map;

@Controller
@RequestMapping ("/FTL") public
class Freemarkercontroller {

    @RequestMapping ("/hello") Public
    String Hello (map<string,object> Map) {
        map.put (' message ', ' Hello,world ');

        return "Ftl/hello";
    }

Then start running.
Freemarker Specific Use reference
http://blog.csdn.net/fhx007/article/details/7902040/
http://blog.csdn.net/tang9140/article/details/39695653

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.