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

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

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

接口我用了@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传参的方式即可:

猜你喜欢

转载自blog.csdn.net/qq_53376718/article/details/141207461