解决:Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type ‘multipart问题

梅秃头 2024-10-19 08:33:01 阅读 62

问题描述:传参格式不正确 

<code>Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'multipart/form-data;boundary=--------------------------083037624092353169827681;charset=UTF-8' is not supported]code>

接口我用了@RequestBody接收参数,也就是必须使用对象的方式传参

@RestController

@RequestMapping("/attendance")

@Api(tags = {"考勤管理"})

public class AttendanceController {

@Autowired

private AttendanceService attendanceService;

@PostMapping("/addAttendance")

public int addAttendance(@RequestBody Attendance attendance){

int addAttendance = attendanceService.addAttendance(attendance);

return addAttendance;

}

}

我使用ApiPost的form-data的方式发送请求,故报:

Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'multipart/form-data;boundary=--------------------------083037624092353169827681;charset=UTF-8' is not supported]错误

改用json传参的方式即可:



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。