加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 01:28:25 所属栏目:大数据 来源:网络整理
导读:我有一个简单的Spring Boot Web应用程序.我正在尝试从服务器接收一些数据. Controller返回一个集合,但浏览器接收空JSON 大括号的数量等于来自服务器的对象数,但其内容为空. @RestControllerpublic class EmployeeController {@Autowiredprivate EmployeeMana

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

@RestController
public class EmployeeController {

@Autowired
private EmployeeManagerImpl employeeManagerImpl;

    @RequestMapping(path="/employees",method = RequestMethod.GET)
    public Iterable

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

enter image description here

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

编辑:
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(){

    }
}
最佳答案
我认为你应该使用Lombok作为类级别而不是字段级别.

@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor    
public class Employee implements Serializable {}

这可以解决您的问题.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读