我正在呼叫傳統的休息端點。在那里,我必須使用方括號author[name]反序列化休息端點中的查詢引數。
問題:是否可以在帶有jackson注釋的方括號(spring boot kotlin)的rest端點中反序列化屬性作者姓名?
@RestController
class AuthorController {
@GetMapping("/author/{id}")
fun getAuthorFromLegacyApi(@PathVariable("id") id: Long, authorDto: AuthorDto) = ResponseEntity.ok(authorDto.name)
}
data class AuthorDto(@JsonProperty("author[name]") val name: String?)
- 代碼:https ://github.com/nusmanov/spring-boot-validation-hibernate/blob/main/src/main/kotlin/com/example/bookvalidation/AuthorController.kt
- 測驗: GET http://localhost:8080/author/5?author[name]=Tom
- 有一個junit測驗見上文
uj5u.com熱心網友回復:
是的,如果您使用以下注釋進行注釋,這是可能authorDto的@RequestParam("author[name]"):
@GetMapping("/author/{id}")
fun getAuthorFromLegacyApi(@PathVariable("id") id: Long, @RequestParam("author[name]") authorDto: AuthorDto) = ResponseEntity.ok(authorDto.name)
uj5u.com熱心網友回復:
怎么用地圖。
@GetMapping("/author/{id}")
fun getAuthorFromLegacyApi(@PathVariable("id") id: Long, @RequestParam authorDto: Map<String, String>): String {
return "Hello $id ${authorDto["author[name]"]} ${authorDto["currency"]}"
}
我試著author/5?author[name]=Tom¤cy=INR得到了回應Hello 5 Tom INR
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/422476.html
標籤:
