JpaRepository
findAll()
renvoie un résultat vide. J'essaie de mettre en place un service de repos en utilisant Spring-boot, la base de données h2 et jpa.
Voici mon schema.sql
CREATE TABLE IF NOT EXISTS `City` (
`city_id` bigint(20) NOT NULL auto_increment,
`city_name` varchar(200) NOT NULL,
PRIMARY KEY (`city_id`));
Mi data.sql
le dossier comprend :
INSERT INTO City (city_id,city_name) VALUES(1,'EDE');
INSERT INTO City (city_id,city_name) VALUES(2,'DRUTEN');
INSERT INTO City (city_id,city_name) VALUES(3,'DELFT');
En City
entité :
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "City")
public class City {
@Id
@GeneratedValue
@Column(name = "city_id")
private Long cityId;
@Column(name = "city_name")
private String cityName;
public Long getCityId() {
return cityId;
}
public void setCityId(Long cityId) {
this.cityId = cityId;
}
public String getCityName() {
return cityName;
}
public void setCityName(String cityName) {
this.cityName = cityName;
}
}
En JpaRepository
l'interface :
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface CityRepository extends JpaRepository<City, Long> {
@Override
List<City> findAll();
}
Et voici mon Contoller
classe
@RestController
@RequestMapping("/city")
public class CityController {
@Autowired
private CityRepository cityRepository;
@RequestMapping(method = RequestMethod.GET, value = "/all")
public List<City> getAllCityList(){
return cityRepository.findAll();
}
}
Qu'est-ce qui ne va pas ? La documentation de référence : Doc de printemps