在JSON响应中获取空值。
模型类:
@Data
@Entity
@Table(name = "TABLE_NAME")
@AllArgsConstructor
@NoArgsConstructor
public class Model{
@EmbeddedId
private MedelId id;
@Embeddable
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class MedelId implements Serializable {
static final long serialVersionUID = 1L;
@Column(name = "first")
private String first;
@Column(name = "last")
private String last;
}
}
DAO界面:
public interface ModelRepository extends CrudRepository<Model, Model.ModelId>
{}
控制器类:
@RestController
@ConditionalOnProperty(value = "api.enabled", havingValue = "true")
@RequestMapping(value = "/api/v1/model", produces = "application/json")
@AllArgsConstructor
public class MyController {
private ModelRepository repo;
@RequestMapping(value = "", method = RequestMethod.GET)
public Iterable<Model> list() {
return repo.findAll();
}
}
结果:
[null,null,null,null,null,null,null,null,null,{"id":{"first":"X","last":"value"}},null]
如果列值之一在表中为空,我将得到空值。
即使一列为空,请帮助我如何获取所有对象