My second Springboot project Web+freemarker

Source: Internet
Author: User

The previous article said, created the first springboot project, now talk about Springboot's Web+freemarker project;

1, first introduce the dependence

        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId> spring-boot-starter-web</artifactid>            <version>${spring.boot.version}</version>        </ dependency>        <dependency>            <groupId>org.springframework.boot</groupId>            < Artifactid>spring-boot-starter-freemarker</artifactid>            <version>${spring.boot.version}</ Version>        </dependency>

2. Create a application class to start the Web

Import Org.springframework.boot.springapplication;import org.springframework.boot.autoconfigure.springbootapplication;/** * Created by LK on 2016/5/7. */@SpringBootApplicationpublic class Samplewebfreemarkerapplication {public    static void Main (string[] args) {        Springapplication.run (Samplewebfreemarkerapplication.class,args);    }}

3. Create a controller class to direct to the view

Import Org.springframework.beans.factory.annotation.value;import Org.springframework.stereotype.Controller; Import Org.springframework.web.bind.annotation.requestmapping;import java.util.date;import java.util.Map;/** * Created by LK on 2016/5/7. */@Controllerpublic class Webcontrpller {    @Value ("${application.message:1234556677}")    private String message = "Hi,hello world ...";    @RequestMapping ("/") Public    String Web (map<string,object> model) {        model.put ("Time", New Date ());        Model.put ("message", this.message);        Return "web";//the content returned is templetes the name of the following file    }}

4, in the resources directory to create the Templates folder, the folder contains two template files

4.1 ERROR.FTL

<! DOCTYPE html>

4.2 WEB.FTL

<! DOCTYPE html>


5, start Samplewebfreemarkerapplication, the browser above the input http://127.0.0.1:8080/can output the page as follows:







My second Springboot project Web+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.