这篇文件主要介绍通过springboot 去创建和提交一个表单。
创建工程
涉及了 web,加上spring-boot-starter-web和spring-boot-starter-thymeleaf的起步依赖。
org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-thymeleaf
创建实体
代码清单如下:
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; } }
创建Controller
@Controllerpublic 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"; } }
页面展示层
src/main/resources/templates/greeting.html
Getting Started: Handling Form Submission Form
架构代码如下 :
Spring Cloud大型企业分布式微服务云架构源码请加企鹅求求:一七九一七四三三八零