最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring MVC @GetMapping和@PostMapping注解的使用方式

 更新時(shí)間:2024年05月28日 09:10:52   作者:云淡風(fēng)輕58  
這篇文章主要介紹了Spring MVC @GetMapping和@PostMapping注解的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

創(chuàng)建HelloWorldController

package com.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class HelloWorldController {
	//只接受get方式的請(qǐng)求
	@GetMapping("/testGetMapping")
	public String testGetMapping(Model model) {
		model.addAttribute("msg","測(cè)試@GetMapping注解");
		return "success";
	}
	//只接受post方式的請(qǐng)求
	@PostMapping("/testPostMapping")
	public String testPostMapping(Model model) {
		model.addAttribute("msg","測(cè)試@PostMapping注解");
		return "success";
	}
}

創(chuàng)建index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>index</title>
</head>
<body>
	<form action="testGetMapping" method="get">
		<button>測(cè)試@GetMapping注解</button>
	</form>
	<br>
	<form action="testPostMapping" method="post">
		<button>測(cè)試@PostMapping注解</button>
	</form>
</body>
</html>

創(chuàng)建success.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>success</title>
</head>
<body>
	${requestScope.msg }
</body>
</html>

啟動(dòng)Tomcat訪問(wèn)index.jsp

點(diǎn)擊【測(cè)試@GetMapping注解】

點(diǎn)擊【測(cè)試@PostMapping注解】

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

巢湖市| 周至县| 吉林市| 建水县| 罗定市| 肃宁县| 连江县| 麦盖提县| 镇坪县| 五大连池市| 嘉善县| 类乌齐县| 广平县| 平山县| 成安县| 托克逊县| 汉源县| 德昌县| 台前县| 公主岭市| 南澳县| 郓城县| 云阳县| 漳州市| 滦南县| 澄江县| 湖南省| 青河县| 偃师市| 尚义县| 罗定市| 青海省| 闽清县| 平果县| 天水市| 临沭县| 安达市| 西峡县| 银川市| 霍林郭勒市| 安陆市|