项目后期遇到uniapp开发的前端项目get\post不能混用,需要统一http请求方式
修改前端封装get请求方式,直接替换为post
public async GET<T>(url: string, queryString?: { [key: string]: number | string }): Promise<T> {
return new Promise<T>((resolve, reject)=>{
this.Request(url, 'POST', queryString || {}).then(({code,message,result})=>{
if(code!==200){
reject(message)
}else{
resolve(result as unknown as T)
}
}).catch((err)=>{
reject(err)
})
})
}
由于不只一个终端调用后端服务,直接对应接口加注解,同时支持get/post请求
@RequestMapping(value = "/getDetail", method = {RequestMethod.GET,RequestMethod.POST})
public Ret getDetail(@ApiParam(name = "id", value = "主键id", required = true) @RequestParam("id") String id) {
if (StrUtil.isBlank(id)) {
return Ret.error("未选中数据");
}
return Ret.ok(baseService.getEntityById(id));
}