[英]How to extract nested json values by using spring boot api call
[英]How are JSON values generated for requests in Spring boot?
在Entity类中,如果我有一个以get <something>()开头的函数,该函数返回一个常数,即使没有声明此类成员变量,它也包含在JSON响应中。 Static
函数不会出现在生成的json中。
我不知道要搜索什么。
我想知道为什么会这样,其潜在机制是什么。
@JsonInclude(JsonInclude.Include.NON_NULL)
@Entity
public class AssignedBook {
@Id
@GeneratedValue( strategy = GenerationType.AUTO )
private Integer id;
@OneToOne
private Book book;
@OneToOne
private Users user;
public static Integer getSomeId() {
return 8;
}
public Integer someAwesomeId() {
return 8;
}
}
我的repository
代码是
@Query(value="select new AssignedBook(id, book) from AssignedBook ab where ab.user.id=:userId")
public List<AssignedBook> findByIdAndBookId(Integer userId);
对于id=15
和一些book
值,这将返回json
[
{
"id": 15,
"book": {
"id": 6,
"name": "Rage of Angels",
"author": "Sidney Sheldon"
},
"someAwesomeId": 8
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.