Spring REST Controller 返回 JSON 和空数据 [已关闭]
2022-09-03 02:43:08
我有一个简单的Spring Boot Web应用程序。我正在尝试从服务器接收一些数据。控制器返回一个集合,但浏览器收到空 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;
}
}
该方法将触发,浏览器将显示:
控制台中没有更多内容。有什么想法吗?
编辑:员工.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(){
}
}