age: 10
gender: m
documents:
- name: "school certificate"
code: "sc"
file:
- name: "transfer certificate"
code: "tc"
file:
- name: "avatar"
code: "avatar"
file:
< /code>
Ich habe zwei Klassen erstellt: < /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>
Ich habe einen Controller hinzugefügt.@RestController
@RequestMapping(value = ["/test"], produces = ["application/json"])
class StudentController {
@PostMapping("/student")
fun student(
@ModelAttribute student: Student
): String? {
return student.name
}
}
< /code>
Ich habe versucht, die API in Postman aufzurufen. src = "https://i.sstatic.net/yuewr.png"/>
Ich habe die Antwort wie unten erhalten.
{
"timestamp": 1589357162828,
"status": 500,
"error": "Internal Server Error",
"message": "Invalid property 'files[0]
Code: Select all
' 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>
Ich bin mir nicht sicher, was hier schief gelaufen ist. Bitte helfen Sie mir dabei.