Spring MVC獲取查詢參數(shù)及路徑參數(shù)代碼實(shí)例
這篇文章主要介紹了Spring MVC獲取查詢參數(shù)及路徑參數(shù)代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
Jsp頁面 query.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>您輸入的id是 ${id}</h1>
</body>
</html>
@RequestParm獲取查詢參數(shù)
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping(value = "/user", method = RequestMethod.GET)
public String user(@RequestParam("id") int id, Map<String, Integer> map) {
map.put("id", id);
return "query";
}
}
以上可訪問.../test/user?id=10測(cè)試
@PathVariable獲取路徑參數(shù)
@Controller
public class TestController {
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
public String user(@PathVariable("id") int id, Map<String, Integer> map) {
map.put("id", id);
return "query";
}
}
以上可訪問.../user/10測(cè)試
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- SpringMVC自定義參數(shù)綁定實(shí)現(xiàn)詳解
- SpringBoot中通過實(shí)現(xiàn)WebMvcConfigurer參數(shù)校驗(yàn)的方法示例
- Spring MVC請(qǐng)求參數(shù)與響應(yīng)結(jié)果全局加密和解密詳解
- 解決SpringMVC接收不到ajaxPOST參數(shù)的問題
- 快速解決SpringMVC @RequestBody 用map接收請(qǐng)求參數(shù)的問題
- 解決SpringMVC Controller 接收頁面?zhèn)鬟f的中文參數(shù)出現(xiàn)亂碼的問題
- springmvc 傳遞和接收數(shù)組參數(shù)的實(shí)例
- axios發(fā)送post請(qǐng)求springMVC接收不到參數(shù)的解決方法
- 聊聊springmvc中controller的方法的參數(shù)注解方式
相關(guān)文章
Mybatis使用XML實(shí)現(xiàn)動(dòng)態(tài)sql的示例代碼
當(dāng)編寫 MyBatis 中復(fù)雜動(dòng)態(tài) SQL 語句時(shí),使用 XML 格式是一種非常靈活的方式,本文主要為大家詳細(xì)介紹了Mybatis使用XML實(shí)現(xiàn)動(dòng)態(tài)sql的具體方法,需要的可以參考下2023-12-12
如何通過idea實(shí)現(xiàn)springboot集成mybatis
這篇文章主要介紹了如何通過idea實(shí)現(xiàn)springboot集成mybatis,使用springboot 集成 mybatis后,通過http請(qǐng)求接口,使得通過http請(qǐng)求可以直接操作數(shù)據(jù)庫,本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-09-09
關(guān)于Java多線程編程鎖優(yōu)化的深入學(xué)習(xí)
本篇文章是關(guān)于Java多線程編程鎖優(yōu)化的深入學(xué)習(xí)總結(jié)內(nèi)容,對(duì)Java鎖優(yōu)化有興趣的朋友跟著學(xué)習(xí)下吧。2018-01-01

