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>