С этим кодом:
City.java
@Entity
@Table(name = "cities")
public class City extends AuditModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@NotBlank
@Column(name = "name")
@Size(min = 3, max = 250)
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "countryId", nullable = false)
@JsonIgnore
private Country country;
// Getters and Setters
...
}
Country.java
@Entity
@Table(name = "countries")
public class Country extends AuditModel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@NotBlank
@Column(name = "name", unique = true)
@Size(min = 3, max = 150)
private String name;
// Getters and Setters
...
}
CityRepository.java
@Repository
public interface CityRepository extends JpaRepository<City, Long> {
}
CountryRepository.java
@Repository
public interface CountryRepository extends JpaRepository<Country, Long> {
}
Мне нужно Получить все города страны, с этим кодом я получу базу данных всех городов:
CityController.java
@GetMapping("/cities")
public Page<City> getAllCities(Pageable pageable) {
return cityRepository.findAll(pageable);
}
Но, как получить все города страны? Как бы это было?