ajax 后台正常执行 错误类型却是404

后台执行importExcel,明明方法执行成功,但是前台却提示404

@RequestMapping("/import")
public Json importExcel(@RequestParam(value="file", required=true) CommonsMultipartFile file,HttpServletRequest req, String exp1 , String modelType){
String[] str=commonServiceI.GetObjectId(3, req);
//str[0]createBy str[1]createDepartment str[2]createArea
List<TjSamilarDto> ltj = tbLicencePorductService.importData(file,exp1,modelType , str[0],str[1],str[2]);
/*String path = "";
if(modelType.equals("危险化学品安全生产许可证")){
path = "/license/ChemicalsPorduct";
}else if(modelType.equals("危险化学品安全使用许可证")){
path ="/license/ChemicalsUse";
}
return path; */
Json j = new Json();
if(ltj.isEmpty()){
j.setExp1("0");
j.setMsg("导入成功!");
}else{
j.setExp1("1");
j.setMsg("有"+ltj.size()+"条数据因与系统中企业名称不匹配导致未导入成功,是否下载查看!");
}
j.setList(ltj);
j.setSuccess(true);
return j;
}

原因:

注解@ResponseBody的作用,这个注解的作用是将函数返回值作为请求返回值。

没有这个注解的话,请求的响应应该是一个页面,不需要页面的话应该加上这个注解。

原文地址:https://www.cnblogs.com/ws5167/p/6050183.html