第 27 講 SpringBoot提交表單資訊
第27講 SpringBoot提交表單資訊
1. 引入依賴:pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2. 引入前端檔案
2.1 greet.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>表單提交頁面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Form</h1>
<form action="#" th:action="@{/greeting}" th:object="${greet}" method="post">
<p>Id: <input type="text" th:field="*{id}" /></p>
<p>Message: <input type="text" th:field="*{content}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
</body>
</html>
2.2 result.html
<!DOCTYPE HTML>
< html xmlns:th="http://www.thymeleaf.org">
<head>
<title>表單提交結果</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>Result</h1>
<hr/>
<p th:text="'id: ' + ${greet.id}"/>
<p th:text="'content: ' + ${greet.content}"/>
<a href="/greeting">Submit another message</a>
</body>
</html>
3. Entity層:Greet
package com.springboot.handlerform.entity;
/**
* @Description:
* @Auther: zrblog
* @CreateTime: 2018-10-21 22:48
* @Version:v1.0
*/
public class Greet {
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;
}
@Override
public String toString() {
return "Greet{" +
"id=" + id +
", content='" + content + '\'' +
'}';
}
}
4. Controller層:GreetController
package com.springboot.handlerform.controller;
import com.springboot.handlerform.entity.Greet;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* @Description:
* @Auther: zrblog
* @CreateTime: 2018-10-21 22:49
* @Version:v1.0
*/
@Controller
@RequestMapping("/")
public class GreetController {
/**
* @descirption: 跳轉到表單頁面
* @param model
* @return
*/
@RequestMapping(value = "greeting",method = RequestMethod.GET)
public String showGreeting(Model model) {
model.addAttribute("greet", new Greet());
return "greet";
}
/**
* @descirption:跳轉到結果頁面
* @param greet
* @return
*/
@RequestMapping(value = "greeting",method = RequestMethod.POST)
public String showGreeting(@ModelAttribute Greet greet) {
return "result";
}
}
5. 測試:
輸入:Id:11,Message: Hello World ,點選"提交"
相關推薦
第 27 講 SpringBoot提交表單資訊
第27講 SpringBoot提交表單資訊 1. 引入依賴:pom.xml <dependency> <groupId>org.springframework.boot
Django第七篇-----如何提交表單
目錄 如何獲取url的資訊 其他可用來反爬的資訊 一個簡單的表單處理 簡單的驗證 第一個表單類 在檢視中使用表單物件 改變欄位的渲染方式 設定最大長度 設定初始值 自定義驗證規則 指定標註 如何獲取url的資訊 HttpRequest 物件中有
ajax提交表單資訊+手機驗證碼註冊
1.手機驗證碼用的是秒嘀科技的手機簡訊功能。 2、前端頁面 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <
Javascript建立虛擬form提交表單資訊
今天遇到了這樣一個問題:在form複選框的表單,有一元件需要使用ajax的post操作來進行動態資料庫更新,那麼在form表單中就有兩個post的操作,當我每次執行ajax的時候,會自動提交form表單的內容,這不是我想要的。 解決方案:更換個思路,通過js獲
ajax form提交表單資訊
寫在前面的話 在使用form表單的時候,一旦點選提交觸發submit事件,一般會使得頁面跳轉,頁面間的跳轉等行為的控制權往往在後端,後端會控制頁面的跳轉及資料傳遞,但是在某些時候不希望頁面跳轉,或者說想要將控制權放在前端,通過js來操作頁面的跳轉或者資料變化。 一般這
springboot提交表單提示NullPointerException
insert r.java ole explicit bce exce ica expected point This application has no explicit mapping for /error, so you are seeing this as a f
第九章 提交表單-使用request庫提交表單、處理cookie等操作
#!/usr/bin/env python # _*_ coding:utf-8 _*_ # 提交一個基本表單 # import requests # # params={'firstname':'Ry
html 提交表單,圖片和文字一起提交,圖片存入伺服器,圖片地址和表單資訊存入資料庫,帶後端php程式碼
html <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no
ajaxform實現檔案和表單資訊一起提交
專案中有個模組提交表單需要提交檔案和其他的一些表單資訊,發現ajaxform實現起來較簡易 function sub(){ var value = $('select option:selected').val() va
無重新整理表單資訊提交,使用HTML5新技術FormData
利用新技術FormData表單資料物件,可以實現快速收集表單資訊,FormData是html5的新技術,在主流瀏覽器都可以使用。 1.傳統的不適用FormData Ajax無重新整理表單提交方式(程式
JSP之——表單資訊和圖片一起提交
// Check that we have a file upload request 檢查是否是表單檔案上請求 boolean isMultipart = ServletFileUpload.i
27.restful中delete請求無法提交表單資料
現在介紹下delete請求無法提交表單資料的解決辦法: 1.在web.xml中新增HiddenHttpMethodFilter過濾器 <!--將POST請求轉換為DELETE或者PUT
PHP提交表單失敗後如何保留填寫的資訊
index.html模板檔案大內容: <html> <head> <title>jQuery Ajax 例項演示</title> </head> <script src="./js/jquery.js" ty
JavaWeb網上圖書商城完整項目--day02-4.regist頁面提交表單時對所有輸入框進行校驗
word except 繼承 stub jstl use cti bmi imp 1、現在我們要將table表中的輸入的參數全部提交到後臺進行校驗,我們提交我們是按照表單的形式提交,所以我們首先需要在table表外面添加一個表單 <%@ page lang
form提交表單
-name 出錯 ajax請求 int data fun java .get 請求 菜鳥的第一篇文章,今天在工作中遇到一個問題。下面來說說,也許很多大神都知道了,但作為菜鳥還是想說說。 對於table表格裏面的數據,如下: [html] view plain copy
php 使用curl 進行簡單模擬提交表單
8.0 bin field this class chrom 提交表單 bsp alt //初始化curl $ch = curl_init(); $url = ‘xxx‘; $option = [ CURLOPT_URL => $url, CURLO
分針網—每日分享:ajax提交表單
print win -c 找不到 用戶 post請求 its -o block ajax提交表單在項目中常用,前臺無論是簡單的html、jsp或者是使用了easyui框架,提交表單都會使用到ajax,extjs框架其實也是使用了ajax只不過對其進行了封裝了,我們使用的時
第9講++數據表的管理和操作
ima val mar pan image add 學生 專業 http 實例1:在學生情況表xsqk中,增加三列: “籍貫”字段,char(12),默認值為“重慶”; “email”字段,varchar(30) ,不能重復; “序號”列,
第8講++數據表和約束的創建(實訓)
play 序號 創建 lda 數據庫切換 tro 約束 http ast 動手操作1:創建kc表和表約束(續) create database xscj go --表示一個批的結束。go 只能獨自占用一行 use xscj
html提交表單到Servlet
mage ima mas png you tps quest getpara col 源碼地址 https://github.com/YouXianMing/Java-Web-Study/tree/master/Servlet-Form 演示效果(註意post與g