Spring Boot 1.5.2, @ModelAttribute не распзнает данные
Помогите понять, в чем проблема? Данные из запроса не парсятся в @ModelAttribute. При этом, идентичный код работает на проекта с версией SpringBoot 2.4.
ajax request:
function editButton(id, name) {
let theModal = $("#updateCompilationModal");
let fieldId = $("#updateCompilationId");
let fieldName = $("#updateCompilationName");
let fieldCover = $("#updateCompilationCover");
fieldId.val(id);
fieldName.val(name);
theModal.modal("show");
$("#updateCompilationBtn").on("click", function () {
let formData = new FormData();
data.append("id", id);
data.append("name", fieldName.val());
data.append("cover", fieldCover.prop("files")[0]);
$.ajax({
method: "PUT",
url: "/api/admin/compilation/update",
contentType: false,
processData: false,
data: formData,
complete: () => {
theModal.modal("hide");
getTable();
},
success: () => {
alert(`${formData.get('id')} - ${formData.get('name')} - ${formData.get('id')}`)
},
error: (xhr, status, error) => {
alert(xhr.responseText + "|\n" + status + "|\n" + error);
}
})
});
}
Dto
package spring.app.dto;
import org.springframework.web.multipart.MultipartFile;
public class TestDto {
private Long id;
private String name;
private MultipartFile cover;
public TestDto() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public MultipartFile getCover() {
return cover;
}
public void setCover(MultipartFile cover) {
this.cover = cover;
}
Controller method with @ModelAttribute
@PutMapping("/update")
public void updateCompilation(@ModelAttribute TestDto dto) throws IOException {
System.out.println("\n\n" + dto.getId() + "\n\n");
// SongCompilation compilation = songCompilationService.getSongCompilationById(dto.getId());
// if (dto.getCover() != null) {
// String coverName = fileUploadService.upload(dto.getCover());
// compilation.setCover(coverName);
// }
// compilation.setName(dto.getName());
// System.out.println("\n\n" + compilation + "\n\n");
// songCompilationService.updateCompilation(compilation);
}