Springboot Unofficial Tutorials | 20th article: processing form submission

Source: Internet
Author: User
Tags reset xmlns

Copyright NOTICE: This article for Bo Master original article, welcome reprint, reprint Please indicate the author, original hyperlink, Bo main address: Http://blog.csdn.net/forezp.

Reprint please indicate the source:
http://blog.csdn.net/forezp/article/details/71023868
This article is from Fang Zhibong's blog

This paper focuses on creating and submitting a form through springboot. Create a project

Involves the web, plus Spring-boot-starter-web and spring-boot-starter-thymeleaf start-dependent.

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactid>spring-boot-starter-test </artifactId>
            <scope>test</scope>
        </dependency>


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

    </dependencies>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Create entity

The code listing is as follows:

public class Greeting {

    private long ID;
    Private String content;

    Public long GetId () {
        return ID;
    }

    public void SetId (long id) {
        this.id = ID;
    }

    Public String getcontent () {
        return content;
    }

    public void SetContent (String content) {
        this.content = content;
    }

}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Create a controller
@Controller public
class Greetingcontroller {

    @GetMapping ("/greeting") public
    String Greetingform (Model Model) {
        Model.addattribute ("greeting", New greeting ());
        return "greeting";
    }

    @PostMapping ("/greeting") public
    String greetingsubmit (@ModelAttribute greeting greeting) {
        return "result";
    }

}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Page Presentation Layer

Src/main/resources/templates/greeting.html

<! DOCTYPE html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Src/main/resources/templates/result.html

<! DOCTYPE html>

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.