做食材的网站,小程序登录入口官网网址,05网语文,二级网站免费建DBAPI如何使用数组类型参数
需求
根据多个id去查询学生信息
API创建
在基本信息标签#xff0c;创建参数ids #xff0c;参数类型选择 Arraybigint 在执行器标签#xff0c;填写sql#xff0c;使用in查询
select * from student where id in
foreach ope…DBAPI如何使用数组类型参数
需求
根据多个id去查询学生信息
API创建
在基本信息标签创建参数ids 参数类型选择 Arraybigint 在执行器标签填写sql使用in查询
select * from student where id in
foreach open( close) collectionids separator, itemitem indexindex#{item}/foreachAPI请求
在请求测试页面点击按钮添加参数框输入3个id发起请求发现返回了3条学生信息 如果想用代码发起请求可以使用以下代码
# python代码
import requests
from urllib import parserequestUrl 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);
});手动取数组参数
也可以手动取参数值修改sql使用ids[0]取数组参数的第一个元素使用ids[1]取数组参数的第二个元素
select * from student where
id #{ids[0]} or id #{ids[1]}