vue使用fetch.js发送post请求java后台无法获取参数值
2021-07-03 20:05
标签:append red odi ica 头文件 set const str export 问题:前台vue使用fetch.js发送post请求后,后台 request.getParameter()无法获取到参数值 思路:查阅后,原因为fetch中头文件Content-type这个Header为application/x-www-form-urlencoded导致request请求中的form data变成request payload 处理办法:后台controller中使用流接受数据后,在进行查询操作既可。 controller代码 vue使用fetch.js发送post请求java后台无法获取参数值 标签:append red odi ica 头文件 set const str export 原文地址:https://www.cnblogs.com/schon/p/9621073.html
/**
* 获取行业大类
*/
export const hangyebrief = industryId => fetch(‘/console/good/industry/findIndustry‘, {
industryId: 2
}, ‘POST‘);
@RequestMapping("findIndustry")
@ResponseBody
public AjaxRes findIndustry( HttpServletRequest request,HttpServletResponse response){
StringBuilder sb = new StringBuilder();
try(BufferedReader reader = request.getReader();) {
char[]buff = new char[1024];
int len;
while((len = reader.read(buff)) != -1) {
sb.append(buff,0, len);
}
}catch (IOException e) {
e.printStackTrace();
}
String idString = sb.toString();
String industryId = idString.substring(idString.indexOf(":")+1,idString.indexOf("}"));
AjaxRes aj = new AjaxRes();
GoodIndustryVo goodIndustry = new GoodIndustryVo();
if (industryId != null && industryId != "") {
goodIndustry.setIndustryId(Integer.parseInt(industryId));
}
List
文章标题:vue使用fetch.js发送post请求java后台无法获取参数值
文章链接:http://soscw.com/index.php/essay/101413.html