spring mvc中的@PathVariable獲得請求url中的動態(tài)參數(shù)
更新時間:2017年02月09日 14:31:57 作者:伴我前行
本文主要介紹了spring mvc中的@PathVariable獲得請求url中的動態(tài)參數(shù)的代碼。具有很好的參考價值,下面跟著小編一起來看下吧
spring mvc中的@PathVariable是用來獲得請求url中的動態(tài)參數(shù)的,十分方便,復(fù)習(xí)下:
@Controller
public class TestController {
@RequestMapping(value="/user/{userId}/roles/{roleId}",method = RequestMethod.GET)
public String getLogin(@PathVariable("userId") String userId,
@PathVariable("roleId") String roleId){
System.out.println("User Id : " + userId);
System.out.println("Role Id : " + roleId);
return "hello";
}
@RequestMapping(value="/product/{productId}",method = RequestMethod.GET)
public String getProduct(@PathVariable("productId") String productId){
System.out.println("Product Id : " + productId);
return "hello";
}
@RequestMapping(value="/javabeat/{regexp1:[a-z-]+}",
method = RequestMethod.GET)
public String getRegExp(@PathVariable("regexp1") String regexp1){
System.out.println("URI Part 1 : " + regexp1);
return "hello";
}
}
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
Java利用條件運算符的嵌套來完成學(xué)習(xí)成績的劃分
這篇文章主要介紹了Java利用條件運算符的嵌套來完成學(xué)習(xí)成績的劃分,需要的朋友可以參考下2017-02-02
ActiveMQ中consumer的消息確認(rèn)機制詳解
這篇文章主要介紹了ActiveMQ中consumer的消息確認(rèn)機制詳解,對于broker而言,只有接收到確認(rèn)指令,才會認(rèn)為消息被正確的接收或者處理成功了,InforSuiteMQ提供以下幾種Consumer與Broker之間的消息確認(rèn)方式,需要的朋友可以參考下2023-10-10
springboot+websocket實現(xiàn)并發(fā)搶紅包功能
本文主要介紹了springboot+websocket實現(xiàn)并發(fā)搶紅包功能,主要包含了4種步驟,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-12-12
MyBatis-Plus詳解(環(huán)境搭建、關(guān)聯(lián)操作)
MyBatis-Plus 是一個 MyBatis 的增強工具,在 MyBatis 的基礎(chǔ)上只做增強不做改變,為簡化開發(fā)、提高效率而生,今天通過本文給大家介紹MyBatis-Plus環(huán)境搭建及關(guān)聯(lián)操作,需要的朋友參考下吧2022-09-09
java: 程序包com.fasterxml.jackson.annotation不存在的解決辦法
當(dāng)我們在導(dǎo)入程序之后,系統(tǒng)給出錯誤提示:java: 程序包com.fasterxml.jackson.annotation不存在,本文主要介紹了Java程序包不存在的三種解決方法,需要的朋友可以參考下2024-02-02

