问题描述
解决办法
网上查阅资料后,发现是因为axios的params参数在序列化时的格式设置不正确而导致的,在axios的配置项中提供paramsSerializer方法可以对params进行序列化:
- 引入qs序列化库
import qs from 'qs'
- 封装请求方法
export const getRequest = (url, params) => {
let accessToken = getStore('accessToken');
return axios({
method: 'get',
url: `${baseApi}${url}`,
params: params,
paramsSerializer: params => {
return qs.stringify(params, { indices: false })
},
headers: {
'accessToken': accessToken
}
});
};
- 调用请求方法
export const getContentByTypeIds = (params) => {
return getRequest('/bridgeMonitorContent/getContentByTypeIds', params)
}
- 后台接口
@GetMapping("/getContentByTypeIds")
@ApiOperation("通过多监测类型查询监测因素")
public Result<List<BridgeMonitorContent>> getContentByTypeIds(@RequestParam List<String> monitorTypeIds){
List<BridgeMonitorContent> contentByTypeId = iBridgeMonitorContentService.getMonitorContentByTypeId(monitorTypeIds);
return new ResultUtil<List<BridgeMonitorContent>>().setData(contentByTypeId);
}