I have the following class:
public class House {
@Id
@GeneratedValue
private long id;
private String title;
private String description;
private String city;
private double price;
private String phoneNumber;
}
I need to make a @GetMapping, where I have to get every attribute of a house except it's city. I tried this:
This is in my repository:
public House findByIdButCity(long id) {
return em.createQuery("SELECT h.title, h.description, h.price FROM House h WHERE h.id = :id", House.class).setParameter("id", id).getSingleResult();
}
And this is in my controller:
@GetMapping("{id}")
public ResponseEntity<House> getAttributesButCityById(@PathVariable long id) {
House house = houseRepository.findByIdButCity(id);
if (house == null)
return ResponseEntity.notFound().build();
else
return ResponseEntity.ok(property);
}