柚子快報(bào)激活碼778899分享:DBAPI如何使用數(shù)組類(lèi)型參數(shù)
柚子快報(bào)激活碼778899分享:DBAPI如何使用數(shù)組類(lèi)型參數(shù)
DBAPI如何使用數(shù)組類(lèi)型參數(shù)
需求
根據(jù)多個(gè)id去查詢學(xué)生信息
API創(chuàng)建
在基本信息標(biāo)簽,創(chuàng)建參數(shù)ids ,參數(shù)類(lèi)型選擇 Array
select * from student where id in
API請(qǐng)求
在請(qǐng)求測(cè)試頁(yè)面,點(diǎn)擊按鈕添加參數(shù)框,輸入3個(gè)id,發(fā)起請(qǐng)求發(fā)現(xiàn)返回了3條學(xué)生信息 如果想用代碼發(fā)起請(qǐng)求可以使用以下代碼
# python代碼
import requests
from urllib import parse
requestUrl = 'http://localhost:8520/api/student/idList'
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
formData = {
"ids": [77,78,79]
}
data = parse.urlencode(formData, True)
response = requests.post(requestUrl, headers = headers, data = data)
print(response.status_code)
print(response.text)
# js 代碼
// npm install axios
// npm install qs
const axios = require('axios');
const qs = require('qs');
const data = qs.stringify({
ids: [77,78,79]
}, { indices: false })
axios({
method: 'post',
url: 'http://localhost:8520/api/student/idList',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: data,
}).then(response => {
console.log(response.data);
}).catch(error => {
console.log(error);
});
手動(dòng)取數(shù)組參數(shù)
也可以手動(dòng)取參數(shù)值,修改sql,使用ids[0]取數(shù)組參數(shù)的第一個(gè)元素,使用ids[1]取數(shù)組參數(shù)的第二個(gè)元素
select * from student where
id = #{ids[0]} or id = #{ids[1]}
柚子快報(bào)激活碼778899分享:DBAPI如何使用數(shù)組類(lèi)型參數(shù)
相關(guān)文章
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。