Spring Boot noob在这里,需要帮助

时间:2018-05-20 15:13:42

标签: rest spring-boot

我正在尝试使用创建端点的Spring Boot创建REST后端应用程序。我正在使用MySQL 5.7。我不知道我在哪里出错,通常是我点击了网址 http://localhost:8080/api/endpoint/all 人员表的内容。但它不是。

人物 - 实体

function evaluate(context){
    var request = context.getCurrentRequest();
    var exchange = request.getLastExchange();
    var body = JSON.parse(exchange.responseBody);
    var key = Object.keys(body)[0];
    var value = body[key].foo;
    return value;
};

PeopleRepo - 存储库

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;
    }
}

PeopleController - Controller

package com.example.filtertest.repo;

import com.example.filtertest.People;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PeopleRepo extends JpaRepository<People, Integer> {
}

Application.properties

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();
    }
}

0 个答案:

没有答案