Springboot Integrated Freemarker

Source: Internet
Author: User

1. Introduction of Freemarker package in Pom.xml

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

2. Add the Freemarker property configuration to the Springboot property profile (application.properties)

 spring.freemarker.allow-request-override=false   Spring.freemarker.cache  =true   Spring.freemarker.check -template-location=true   Span style= "COLOR: #000000" > #spring. Freemarker.charset  =utf-8 Spring.freemarker.content -type=text/html spring.freemarker.expose -  Request-attributes=false   Spring.freemarker.expose -session-attributes=false   Spring.freemarker.expose -spring-macro-helpers= false    Spring.freemarker.prefix  = Spring.freemarker.suffix  =.FTL 

PS: Here is a question, spring.freemarker.charset=utf-8 I this opportunity error, still do not know why.

3. Writing control classes

 PackageCom.test.springboot.control;ImportJava.util.Map;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.servlet.ModelAndView; @Controller Public classFreemarkercontrol {@RequestMapping (value= "/hellofreemarker")//direct access to the path without adding the project name     PublicModelandview Sayfreemarkerhello (map<string,object>map) {Modelandview mv=NewModelandview ("Hello");//instantiate a template viewMap.put ("msg", "Hello Freemarker XXX");//assigning values to parameters        returnmv//return template View Object    }}

PS: @RequestMapping (value= "/hellofreemarker") can also be written in @requestmapping ("/hellofreemarker") This way

4. Writing the FTL page

<! DOCTYPE html>

5. Start the Springboot startup file and start the file as follows

 Package Com.test.springboot; Import org.springframework.boot.SpringApplication; Import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication  Public class springbootapplication {    publicstaticvoid  main (string[] args) {        Springapplication.run (springbootapplication. class , args);}    }

6. After successful startup, the Access path

Http://localhost:8088/hellofreemarker

Here the basic configuration is successful.

Encountered a problem: when the directory structure as shown in the left image, that is, the white package icon style, referring to the 44859223 method of normal display as follows right

But can not access, always 404 error as shown, have not found the reason for subsequent updates!!

Springboot Integrated Freemarker

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.