根据多个id去查询学生信息
ids
,参数类型选择 Array
select * from student where id in
<foreach open="(" close=")" collection="ids" separator="," item="item" index="index">#{item}foreach>
# 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);
});
ids[0]
取数组参数的第一个元素,使用ids[1]
取数组参数的第二个元素select * from student where
id = #{ids[0]} or id = #{ids[1]}