Jan*_*ake 4 java hibernate spring-boot
我得到了一个从 db 调用返回的列表。
List<employee> list = empolyeeRepository.findByEmployeeId(id);
Run Code Online (Sandbox Code Playgroud)
列表包含员工 pojo 类对象。我想删除一个属性,让我们在从休息电话返回时说“员工银行账户号”。
@RequestMapping(value = "/employeeInformation/{id}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public List<Employee> getEmployeeInformation(@PathVariable("id") String id) throws Exception {
return empolyeeRepository.findByEmployeeId(id);
}
Run Code Online (Sandbox Code Playgroud)
是否有任何注释或良好做法可以做到这一点?
正如上面的评论中提到的,您不能在运行时删除已编译类的字段。假设您必须从生成的 json 中排除某些字段,我会看到两个选项:
@JsonIgnore如果您使用的是 Jackson(spring boot 中的默认值),则可能会放在 getter 方法上。第二种方法需要的代码要少得多,但第一种方法更灵活。| 归档时间: |
|
| 查看次数: |
17545 次 |
| 最近记录: |