国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - SpringBoot之Controller的使用詳解

SpringBoot之Controller的使用詳解

2020-12-16 13:27ren-zhe Java教程

本篇文章主要介紹了SpringBoot之Controller的使用詳解,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。

本文介紹了 springboot之controller的使用,分享給大家,具體如下:

1.@controller:處理http請(qǐng)求

2.@restcontroller:spring4之后新加的注解,原來(lái)返回json需要@responsebody配合@controller

3.@requestmapping 配置url映射

1.現(xiàn)在有一個(gè)需求(即可以使用localhost:8080/hello和localhost:8080/hi都可以訪問(wèn)):

 
?
1
 
2
3
4
5
6
7
@restcontroller
public class hellocontroller {
  @requestmapping(value={"/hello","hi"},method = requestmethod.get)//使用集合設(shè)置
  public string say(){
    return "hello spring boot";
  }
}

springboot獲取請(qǐng)求參數(shù)

1.@pathvariable–>獲取url中的數(shù)據(jù)

2.@reqeustparam–>獲取請(qǐng)求參數(shù)的值,可以設(shè)置默認(rèn)值以及是否必傳

3.@getmapping–>組合注解(相當(dāng)于@requestmapping同時(shí)限定請(qǐng)求方法為get 方式)

1.第一種方式:

假如http://localhost:8080/hello為請(qǐng)求,springboot為需要傳遞的參數(shù):http://localhost:8080/hello/spingboot,獲取此種請(qǐng)求的參數(shù)的方式,使用@pathvariable注解

 
?
1
 
2
3
4
5
6
7
@restcontroller
public class hellocontroller { 
  @requestmapping("/hello/{params}")//獲取請(qǐng)求為http://localhost:8080/hello/xxx 類型的參數(shù)
  public string hello(@pathvariable("params") string paramsstr) {//聲明一個(gè)變量接收請(qǐng)求中的參數(shù)
    return "parameter is "+paramsstr;
  }
}

運(yùn)行程序,輸入http://localhost:8080/hello/spingboot進(jìn)行測(cè)試:

SpringBoot之Controller的使用詳解

2.第二種方式:

獲取請(qǐng)求為http://localhost:8080/hello?params=spingboot類型的參數(shù),使用@requesparam注解,使用方法為@requesparam("請(qǐng)求中的參數(shù)名params")

 
?
1
 
2
3
4
5
6
7
8
@restcontroller
public class hellocontroller {
  //獲取請(qǐng)求為http://localhost:8080/hello?xxx=xxx類型的參數(shù)
  @requestmapping("/hello")
  public string hello(@requestparam("params") string paramsstr) {//requestparam中的參數(shù)名稱與請(qǐng)求中參數(shù)名稱要一致 
    return "parameter is "+paramsstr;
  }
}

如:@requestparam(value="item_id",required=true) string id

@requestparam中的其他屬性:

--required:是否必須,默認(rèn)是true,表示請(qǐng)求中一定要有相應(yīng)的參數(shù),否則將報(bào)錯(cuò)

--defaultvalue:默認(rèn)值,表示如果請(qǐng)求中沒(méi)有同名參數(shù)時(shí)的默認(rèn)值

啟動(dòng)程序,輸入http://localhost:8080/hello?params=spingboot:

SpringBoot之Controller的使用詳解

對(duì)于@requestmapping(value="/hello",method = requestmethod.get)可以使用:@getmapping(value="/hello"),如果是post的話就是用@postmapping

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://blog.csdn.net/qq_35508033/article/details/71893371?utm_source=gold_browser_extension

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产在线a | 九九热视频在线观看 | 亚洲视频精品在线 | 免费中文字幕 | 午夜看片| 久久精品亚洲 | 日韩在线观看中文字幕 | 国产精品香蕉在线观看 | 中文字幕一区二区三区四区不卡 | 激情综合在线 | 有码在线| 国产精品久久久久久一区 | 亚洲国产精品一区在线 | 成人av一级片 | 欧美狠狠操 | 欧美久久久久久久久久久久久久 | 91色在线观看 | 四虎免费看黄 | 在线观看一区二区精品 | 亚洲天天干 | 精久久| 欧美影 | 午夜成人在线视频 | 91.成人天堂一区 | 91在线影视| 国产精品日韩欧美一区二区三区 | 国产一区二区精品在线观看 | 欧美free性丝袜xxxxhd | 一区二区国产在线观看 | 精品国产乱码久久久久久1区2区 | 亚洲日韩欧美一区二区在线 | 91久久综合亚洲鲁鲁五月天 | 涩涩一区| 亚洲精品无码专区在线播放 | 日本中文字幕在线播放 | 午夜视频在线 | 一级特黄a免费观看视频 | 在线国产一区 | 国产资源在线观看视频 | 亚洲午夜av| 国产在线a |