你可以尝试使用@JsonView注解来解决:
@GetMapping("{id}")
@JsonView({Name.class, Age.class})
public Student findById(@PathVxxxx Long id) {
return xxx;
}
class Student {
private Long id;
@JsonView(Name.class)
private String name;
@JsonView(Age.class)
private Integer age;
}
interface Name {}
interface Age {}
此时,进行该方法的请求时,则仅返回name及age字段。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…