First, Introduction
Spring Boot's Web application development is based on spring MVC.
Spring boot is based on spring default, and the following features are added for automatic configuration:
1, including the contentnegotiatingviewresolver and beannameviewresolver beans.
2. Support for static resources, including support for Webjars.
3, automatic registration Converter,genericconverter,formatter beans.
4, support for Httpmessageconverters.
5, automatic registration messagecoderesolver.
6, the support of static index.html.
7, the support of custom favicon.
8. Active use of Configurablewebbindinginitializer beans
Second, the choice of template engine
Freemarker
Thymeleaf
Velocity (deprecated after version 1.4, deprecated after Spring Framework version 4.3)
Groovy
Mustache
Note: JSP should be avoided as much as possible for the following reasons:
1, JSP can only be packaged as: War format, does not support jar format, only in the standard container run (Tomcat,jetty can)
2, the embedded jetty currently does not support JSPs
3, Undertow does not support JSPs
4. The JSP custom error page cannot overwrite the spring boot default error page
Third, the use of Freemarker
Create a new project, tick Freemarker, DevTools (easy to develop)
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/98/AA/wKioL1k_azHgXoASAABPQCG3DAQ480.jpg "title=" 1497328358 (1). jpg "alt=" wkiol1k_azhgxoasaabpqcg3daq480.jpg "/>
The Freemarker configuration is automatically added to the Pom.xml:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-freemarker</artifactid></dependency>
Webcontroller.java:
package com.example.demo.controller;import org.slf4j.logger;import org.slf4j.loggerfactory; import org.springframework.stereotype.controller;import org.springframework.ui.model;import org.springframework.web.bind.annotation.requestmapping;/** * created by dell on 2017/6/13. */@Controller @requestmapping ("/web") public class webcontroller { private static final logger logger = loggerfactory.getlogger ( Webcontroller.class); @RequestMapping ("/index") public String index (Model model) { logger.info (" This is a controller "); model.addattribute (" title "," I am an example "); return "index"; // note, do not add/,linux to the front. }}
INDEX.FTL:
<! Doctype html>
Description
1, the view default access templates below, such as "index", then: Find INDEX.FTL under Templates
2, CSS, JS, img and other static resources are found under the static, such as <link href= "/css/index.css" rel= "stylesheet"/>, you are looking for static under the CSS under the Index.css file
This article is from "I Love Big gold" blog, please be sure to keep this source http://1754966750.blog.51cto.com/7455444/1934891
Springboot (5): Web Development-Template engine Freemarker