this the code:
@RequestMapping(value="/find/city={city}", method=RequestMethod.GET)
public List<Master_City> getCity(@PathVariable String city)
{
return City_Repository.findByCityLikeIgnoreCase(city);
}
显示所有JSON字段。我只需要2个字段。
答案 0 :(得分:0)
只需将@JsonIgnore注释添加到您不想发送的字段的getter中 例如:
class MasterCity{
private String contact;
private String address;
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
@JsonIgnore
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
@RequestMapping(value="/find/city={city}", method=RequestMethod.GET)
public List<Master_City> getCity(@PathVariable String city)
{
return City_Repository.findByCityLikeIgnoreCase(city);
}
现在它将忽略地址