age: 10
gender: m
documents:
- name: "school certificate"
code: "sc"
file:
- name: "transfer certificate"
code: "tc"
file:
- name: "avatar"
code: "avatar"
file:
< /code>
Я создал два класса: < /p>
class Student {
var name: String = ""
var age: Int = 0
var gender: String = "m"
var files: List? = null
}
class Document {
var name: String? = null
var code: String? = null
var file: MultipartFile? = null
}
< /code>
Я добавил контроллер.@RestController
@RequestMapping(value = ["/test"], produces = ["application/json"])
class StudentController {
@PostMapping("/student")
fun student(
@ModelAttribute student: Student
): String? {
return student.name
}
}
< /code>
Я попытался позвонить в API в почте. src = "https://i.sstatic.net/yuewr.png"/>
Я получил ответ, как ниже.
{
"timestamp": 1589357162828,
"status": 500,
"error": "Internal Server Error",
"message": "Invalid property 'files[0]
Код: Выделить всё
' of bean class [com.example.Student]: Property referenced in indexed property path 'files[0][code]' is neither an array nor a List nor a Map; returned value was [com.example.Document@1801d05f]",
"path": "/test/student"
}
< /code>
Я не уверен, что здесь пошло не так. Пожалуйста, помогите мне в этом.
Подробнее здесь: [url]https://stackoverflow.com/questions/61769499/spring-boot-upload-multiple-files-with-attributes[/url]