--- title: '表格傳送資料到後端,尚未進行驗證機制(validation),尚未建立資料庫' disqus: hackmd --- ###### tags: `frontend` `SpringBoot` 表格傳送資料到後端,尚未進行驗證機制(validation),尚未建立資料庫 === [TOC] ## 適用場景 希望寫一個註冊使用者的註冊表單,最後把使用者的資訊打印在Eclipse 的console上面 html上面有個表單,想要把他的資料傳送到後端去,最後希望印在console上面, ## 撰寫順序 1. 寫出html 的form,放的位置要記得喔 2. 寫出後端可以接收的controller 3. 寫出html 顯現註冊後的使用者名字,這部分需要套件thymeleaf來幫忙 ## 檔案結構目錄  並不會全部用到所有檔案 ## 概述 我們到底要做甚麼東西呢? 一個可以註冊的表單,並且把註冊的資訊傳遞到後端 由於此專案只有打印到console,所以不需要放置資料庫連線設定在application.properties裡面 我們需要的東西大概主要指有兩個 1. html(負責傳送註冊資料) 2. controller負責打印(負責接收註冊資料) ## 每個package的功用 ## 程式碼部分 ### pom.xml ```xml= <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <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> ``` ### html直接submit的那種 ## 參考連結 [FormData](https://javascript.info/formdata) [靠js去做submit](https://www.w3school.com.cn/tiy/t.asp?f=hdom_form_submit) [Thymleaf](https://springhow.com/thymeleaf-form-handling/)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up