在做导出接口时,对post方法的该传参中加了@RequestBody注解,会将查询条件的content-Type设置为application/json
@PostMapping("/export")
public void overtimeExport(HttpServletResponse response, @RequestBody SysUser sysUser){
List<SysUser> list=SysUserService.getUserInfo(sysUser);
ExcelUtil<SysUser> util = new ExcelUtil<>(SysUser.class);
util.exportExcel(response,list,"用户信息列表");
}
当前端调用接口时,Ajax使用post方法时默认请求头中content-Type是application/x-www-form-urlencoded;charset=UTF-8,此时会报错:
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
则解决方法,要么后端去掉@RequestBody注解,要么前端指定请求头的content-Type为application/json
另:postman测试导出接口的方法
查询条件需写在body的json格式中
标签:content,导出,接口,RequestBody,application,json,Type From: https://www.cnblogs.com/lal520/p/17623225.html