我使用springboot作为api rest,vuejs位于前端。
我的模型课程是:
@EqualsAndHashCode(callSuper = true)
@Entity
@Data
public class Habitante extends Persona {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@NotBlank
@Pattern(regexp = "^[HM]$")
private String sexo;
@NotBlank
private String nacionalidad;
@Valid
@ManyToOne
@JsonIdentityReference(alwaysAsId = true)
private Vivienda Vivienda;
@Valid
@ManyToOne
@JsonIdentityReference(alwaysAsId = true)
private Identificacion tarjetaIdentificacion;
@Column(unique = true)
private String identificacion;
}
和
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Solicitud implements Serializable {
private static final long serialVersionUID = 9178661439383356177L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@Past
private Date fecha;
@Valid
@ManyToOne
private Habitante solicitante;
private String justificacion;
@Pattern(regexp = "^[AM]$")
@NotBlank
private String tipo;
@Pattern(regexp = "^(ACR|AIM|MV|MD|MRE)$")
@NotBlank
private String subtipo;
// El estado puede ser pendiente (P), aceptada (A), rechazada (R) y cancelada (C)
@NotBlank
@Pattern(regexp = "^[ACRP]$")
private String estado;
// Sólo para menores de edad que lo quieran añadir o para personas con tarjeta identificativa
@Pattern(regexp = "^(\\d{8}\\w)|(\\d{7}[XYZ])$")
private String identificacion;
@Valid
@ManyToOne
private Identificacion tipoIdentificacion;
private String nombre;
private String primerApellido;
private String segundoApellido;
@Valid
@ManyToOne
private Vivienda vivienda;
@Past
private Date fechaNacimiento;
@Valid
@OneToMany
private List<Documento> documentos;
}
当我试图发送一个新的 Solicitud
像这样使用axios:
const solicitud = {
fecha: new Date(),
solicitante: {
id: props.userLogged.id
},
estado: 'P',
justificacion: '',
tipo: opcion.value,
subtipo: subOpcion.value,
nombre: nombre.value,
primerApellido: primerApellido.value,
segundoApellido: segundoApellido.value,
fechaNacimiento: fechaNacimiento.value,
tipoIdentificacion: { id: tipoIdentificacion },
// identificacion: tIdentificacion,
documentos: [],
};
await axios.post(`${BASE_URL}solicitud/habitante/new`, solicitud);
@PostMapping(value = "/habitante/new")
public Respuesta nuevaSolicitud(@RequestBody Solicitud solicitud){ ... }
在Spring,我没有得到全部 Habitante
对象,只有 id
,同样的事情也发生在房产上 vivienda
在另一个请求中,我得到:
是否有任何方法可以在控制器上获取整个对象?
暂无答案!
目前还没有任何答案,快来回答吧!