Я пытаюсь создать приложение REST backend с помощью Spring Boot, которое создает конечные точки.Я использую MySQL 5.7.Я не знаю, где я ошибаюсь, как правило, если я нажимаю на URL http://localhost:8080/api/endpoint/all содержимое таблицы People.Но это не так.
People - Entity
package com.example.filtertest;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@Entity
@Table(name = "people")
public class People {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@NotNull
Integer id;
String name;
String city;
Double income;
Integer age;
public People() {
}
public People(String name, String city, Double income, Integer age) {
this.name = name;
this.city = city;
this.income = income;
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public Double getIncome() {
return income;
}
public void setIncome(Double income) {
this.income = income;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
PeopleRepo - Репозиторий
package com.example.filtertest.repo;
import com.example.filtertest.People;
import org.springframework.data.jpa.repository.JpaRepository;
public interface PeopleRepo extends JpaRepository<People, Integer> {
}
PeopleController - контроллер
package com.example.filtertest.controller;
import com.example.filtertest.People;
import com.example.filtertest.repo.PeopleRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController(value="/api/endpoint")
@CrossOrigin(origins = "http://localhost:4200", allowedHeaders = "*")
public class PeopleController {
@Autowired
private PeopleRepo peopleRepo;
@GetMapping("/all")
public List<People> getAll() {
return peopleRepo.findAll();
}
}
Application.properties
spring.datasource.url = jdbc:mysql://localhost:3306/learning
spring.datasource.username = root
spring.datasource.password = root
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = validate