相关疑难解决方法(0)

Spring REST Controller返回带有空数据的JSON

我有一个简单的Spring Boot Web应用程序.我正在尝试从服务器接收一些数据.Controller返回一个集合,但浏览器接收空JSON - 大括号的数量等于来自服务器的对象数,但其内容为空.

@RestController
public class EmployeeController {

@Autowired
private EmployeeManagerImpl employeeManagerImpl;

    @RequestMapping(path="/employees", method = RequestMethod.GET)
    public Iterable<Employee> getAllEmployees() {
        Iterable<Employee> employeesIterable = employeeManagerImpl.getAllEmployees();
        return employeesIterable;
    }
}
Run Code Online (Sandbox Code Playgroud)

该方法触发,浏览器显示:

在此输入图像描述

在控制台中没有更多.有任何想法吗?

编辑:Employee.java

@Entity
public class Employee implements Serializable{

    private static final long serialVersionUID = -1723798766434132067L;

    @Id
    @Getter @Setter 
    @GeneratedValue
    private Long id;

    @Getter @Setter
    @Column(name = "first_name")
    private String firstName;

    @Getter @Setter
    @Column(name = "last_name")
    private String lastName;

    @Getter @Setter
    private BigDecimal salary;

    public Employee(){

    }
}
Run Code Online (Sandbox Code Playgroud)

java spring json spring-boot spring-web

13
推荐指数
2
解决办法
9432
查看次数

标签 统计

java ×1

json ×1

spring ×1

spring-boot ×1

spring-web ×1