Required request parameter 'cityId' for method parameter type Long is not present
时间: 2023-12-31 13:22:36 浏览: 95
这个错误通常是因为在请求中没有提供必需的参数cityId,而在代码中的方法参数中却要求必须提供该参数。解决这个问题的方法是在请求中提供必需的参数cityId。具体方法取决于你是如何发送请求的,可以通过在URL中添加查询参数或在请求正文中添加JSON或表单数据来提供参数。如果你确定已经提供了必需的参数,那么可能是参数名称不匹配或参数类型不正确导致的错误。在这种情况下,你需要检查请求中提供的参数名称和类型是否与代码中的方法参数匹配。
相关问题
{ label: '省', field: 'provinceId', colProps: { span: 12 }, required:true, component: 'ApiSelect', componentProps: ({ formActionType }) => { return { api: optionSegmentApi, showSearch: true, optionFilterProp: 'label', resultField: 'items', labelField: 'name', valueField: 'id', onChange: async (e: any) => { const { updateSchema,setFieldsValue } = formActionType; const cityList = await optionCityApi(e); // window.localStorage.setItem('cityList',JSON.stringify(cityList)) window.console.log('cityList',cityList) await updateSchema({ field: 'cityId', componentProps: { options:[] }, }).then(()=>{ updateSchema({ field: 'cityId', componentProps: { options: cityList, } }) }) // 设置cityId的值为空,避免数据累加 setFieldsValue({ cityId: '' }); // 重新设置cityId的选项 setFieldsValue({ cityId: cityList[0]?.id }); }, }; }, }, { label: '市', field: 'cityId', required:true, component: 'Select', componentProps: { fieldNames: { label: 'name', key: 'id', value: 'id', }, showSearch: true, optionFilterProp: 'label', // options:JSON.parse(window.localStorage.getItem('cityList')), }, colProps: { span: 12 }, },我已经清空了。打印的数据是新的数据。但是前端展示还是累加
根据你提供的代码,我发现在更新`cityId`下拉列表的时候,使用了两次`updateSchema`,而第二次调用时没有等第一次调用的`Promise`返回结果,这可能会导致数据错乱或累加的情况。建议将两次调用合并为一次,像这样:
```
await updateSchema({
field: 'cityId',
componentProps: {
options: cityList,
},
// 设置cityId的值为空,避免数据累加
value:'',
}).then(()=>{
// 重新设置cityId的选项
setFieldsValue({ cityId: cityList[0]?.id });
})
```
这样可以确保每次更新`cityId`下拉列表时,先将其选项设置为空,再设置新的选项列表,最后将`cityId`的值设置为第一个选项的值,这样就可以避免数据累加的问题了。
fetch("https://can.ctrip.com/api/product/hotelfilter", { "headers": { "accept": "application/json, text/javascript, */*; q=0.01", "accept-language": "zh-CN,zh;q=0.9", "authorization": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3MDQxMiIsInVzZXJuYW1lIjoiWFJUWDA5MjUiLCJ1dWlkIjoiTG9naW5jMTQ4M2NiNy1lMDA0LTQyMWMtYWM2MS04YjVmOGYyYjZiYTciLCJyb2xlTmFtZXMiOlsiUk9MRV9BRE1JTiJdLCJleHAiOjE2NzQwMzU4MDZ9.4uxlgs29BIVP-KKlyHtOkTV-9Dv7muB65MCnA4nstPaVRwqHhT3Imw-8b8eHUdKZhY-l1Z7OHxsw2jAS2NWShQ", "content-type": "application/json", "sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\"", "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": "\"Windows\"", "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-origin", "syslng": "zhCN", "x-requested-with": "XMLHttpRequest" }, "referrer": "https://can.ctrip.com/index", "referrerPolicy": "strict-origin-when-cross-origin", "body": "{\"cityid\":\"2\",\"countryid\":\"1\",\"currency\":\"CNY\"}", "method": "POST", "mode": "cors", "credentials": "include" }); 转成 python 代码
import requests
url = "https://can.ctrip.com/api/product/hotelfilter"
headers = {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-language": "zh-CN,zh;q=0.9",
"authorization": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI3MDQxMiIsInVzZXJuYW1lIjoiWFJUWDA5MjUiLCJ1dWlkIjoiTG9naW5jMTQ4M2NiNy1lMDA0LTQyMWMtYWM2MS04YjVmOGYyYjZiYTciLCJyb2xlTmFtZXMiOlsiUk9MRV9BRE1JTiJdLCJleHAiOjE2NzQwMzU4MDZ9.4uxlgs29BIVP-KKlyHtOkTV-9Dv7muB65MCnA4nstPaVRwqHhT3Imw-8b8eHUdKZhY-l1Z7OHxsw2jAS2NWShQ",
"content-type": "application/json",
"sec-ch-ua": "\"Not?A_Brand\";v=\"8\", \"Chromium\";v=\"108\", \"Google Chrome\";v=\"108\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"syslng": "zhCN",
"x-requested-with": "XMLHttpRequest"
}
data = {"cityid":"2","countryid":"1","currency":"CNY"}
response = requests.post(url, headers=headers, json=data)
print(response.json())
阅读全文