这篇文件主要介绍通过springboot 去创建和提交一个表单。
创建工程
涉及了 web,加上spring-boot-starter-web和spring-boot-starter-thymeleaf的起步依赖。
1 | <dependencies> |
创建实体
代码清单如下:
1 |
|
创建Controller
1 | @Controller |
页面展示层
src/main/resources/templates/greeting.html
1 |
|
src/main/resources/templates/result.html
1 |
|
启动工程,访问ttp://localhost:8080/greeting:
点击submit:
参考资料
https://spring.io/guides/gs/handling-form-submission/
源码下载
https://github.com/forezp/SpringBootLearning
优秀文章推荐:
- 更多springboot 教程:springBoot非官方教程 | 文章汇总
- 更多springcoud 教程:史上最简单的 SpringCloud 教程 | 文章汇总