後台介面的入參傳遞方式設定的幾種區別對別

2021-10-06 13:34:38 字數 1303 閱讀 2610

介面的入參根據後端的定義可以分為三種:

1.入參放在路徑上,介面封裝像下面這個:

@responsebody

public commonresult changeparentadviserinfo(@pathvariable(value = "userstudentid") long userstudentid,

@pathvariable(value = "operatorid") long operatorid)

這裡主要是通過註解 @pathvariable來指定引數在路徑上。

注意點:如果引數是非必填,則不適合用路徑的方式傳遞。

請求時的入參是這樣的: 

localhost:8080/opsapi/user/ops/change/parentinfo/5839922410632/2
2.入參放在請求路徑的問號後面,介面封裝像下面這個

@responsebody

public commonresult changeparentadviserinfo(@requestparam(value = "newadviserid", required = false) long newadviserid,

@requestparam(value = "newxgid", required = false) long newxgid)

return userservice.changeparentadviserorxginfo( newadviserid,newxgid);

}這裡主要通過註解@requestparam,需要注意的是如果引數非必填,則要顯示把required=false寫上,預設為true,必填的!

請求的入參是這樣的:

localhost:8080/opsapi/user/ops/change/parentinfo?newadviserid=16
3.入參單獨封裝為json,作為乙個實體傳遞,介面封裝向下面這樣

@responsebody

public commonresultregister(@requestbody @validated userregisterparam userregisterparam)

主要通過注釋: @requestbody實現。當然@validated是校驗的註解。

請求的入參是這樣的:

三者的使用注意點主要有兩個:

1.針對路徑方式,入參必須為必傳的才行。如果非必填,路徑成啥了,會404,找不到資源。

2.針對路徑問好後的,註解預設是必填字段,如果非必填,需要顯示宣告其required的值為false.

Vue axios 請求後台介面的幾種方式

2.post 方式 3.put 方式 4.patch 方式 5.delete 方式 axios 是乙個基於 promise 的 http 庫,可以用在瀏覽器和 node.js 中。安裝axios npm install axios 在main.js頁面引入axios,並配置預設請求介面 配置axio...

Linux 入參驗證,引數傳遞驗證

linux 運維以及指令碼乾貨 歡迎分享,歡迎folk 技巧 先把符合條件的情況列舉出來,然後,比如有四個新增符合情況,a1,a2,a3,a4 則其反面是 a1 a2 a3 a4 此條件下用於引數驗證 showruntime set x tmp echo 2 grep 0 9 0 9 0 9 0 9...

Mybatis多引數傳遞入參四種處理方式

mutiparameter resulttype com.jt.mybatis.entity.user select from user where id and username select 利用mybatis註解方式 sql語句比較簡單時推薦此方式 select select from use...