我正在使用 spring boot 3,我有一个名为 UniteEnseignement 的实体,看起来像这样:
@Getter
@Setter
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "UNITE_ENSEIGNEMENT")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class UniteEnseignement implements Identifiable<UniteEnseignementId>{
@Valid
@NotNull(message = "codeFormation est Requis!")
@EmbeddedId
private UniteEnseignementId id;
@NotNull(message = "noEnseignant est Requis!")
@ManyToOne(fetch = FetchType.EAGER, optional = false)
@JoinColumn(name = "NO_ENSEIGNANT", nullable = false)
@JsonIgnoreProperties({"hibernateLazyInitializer"})
private Enseignant noEnseignant; }
UniteEnseignementId :
@Getter
@Setter
@Embeddable
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UniteEnseignementId implements Serializable {
private static final long serialVersionUID = 8208650618508750641L;
@Column(name = "CODE_FORMATION", nullable = false, length = 8)
@NotBlank(message = "codeFormation est Requis!")
private String codeFormation;
@Column(name = "CODE_UE", nullable = false, length = 8)
@NotBlank(message = "codeUe est Requis!")
private String codeUe;
}
实体少尉:
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Entity
@Table(name = "ENSEIGNANT")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class Enseignant implements Identifiable<Long>{
@Id
@Column(name = "NO_ENSEIGNANT", nullable = false)
@SequenceGenerator(name="ens_seq", sequenceName = "ens_seq", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ens_seq")
private Long id;
@OneToMany(mappedBy = "noEnseignant", fetch = FetchType.LAZY)
@JsonIgnoreProperties({"hibernateLazyInitializer"})
@JsonBackReference(value="noEnseignant")
@JsonIgnore
private List<UniteEnseignement> listUE;
}
我想调用我的控制器:UEController
@RestController
@RequestMapping("/unites_enseignement")
public class UEController extends BaseController<UniteEnseignement, UniteEnseignementId> {
@Autowired
public UEController(UEService ueService) {
super(ueService);
}
@Override
public List<UniteEnseignement> getAll() {
for( UniteEnseignement ue : super.getAll())
System.out.println(ue.getNoEnseignant());
return super.getAll();
}
}
在我的控制台中它正确地打印出来:
[UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=ISI)noEnseignantEnseignant{id=1, type='MCF', sexe='H', nom='S', prenom='P'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Ingénierie des Systèmes d'Information', semestre='9 ', description='null', nbhCm=30, nbhTd=30, nbhTp=30}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=IDL)noEnseignantEnseignant{id=1, type='MCF', sexe='H', nom='S', prenom='P'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Ingénierie de Développement Logiciel', semestre='9 ', description='null', nbhCm=20, nbhTd=20, nbhTp=20}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=J2EE)noEnseignantEnseignant{id=2, type='MCF', sexe='H', nom='LL', prenom='MM'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Java/J2EE', semestre='9 ', description='null', nbhCm=20, nbhTd=20, nbhTp=20}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=SR)noEnseignantEnseignant{id=2, type='MCF', sexe='H', nom='LL', prenom='MM'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Systèmes Répartis', semestre='10 ', description='null', nbhCm=20, nbhTd=20, nbhTp=20}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=EDE)noEnseignantEnseignant{id=3, type='PRAST', sexe='H', nom='Jean', prenom='Patrick'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Environnement de Développement', semestre='9 ', description='null', nbhCm=0, nbhTd=0, nbhTp=48}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=WEB)noEnseignantEnseignant{id=3, type='PRAST', sexe='H', nom='Jean', prenom='Patrick'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Langages du WEB', semestre='9 ', description='null', nbhCm=20, nbhTd=20, nbhTp=20}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=CO)noEnseignantEnseignant{id=5, type='MCF', sexe='H', nom='KER', prenom='Pat'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Conception Objet', semestre='9 ', description='null', nbhCm=20, nbhTd=20, nbhTp=20}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=PCO)noEnseignantEnseignant{id=1, type='MCF', sexe='H', nom='S', prenom='P'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Préparation au Contexte de l'Offshore', semestre='10 ', description='null', nbhCm=16, nbhTd=16, nbhTp=16}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=MMM)noEnseignantEnseignant{id=1, type='MCF', sexe='H', nom='S', prenom='P'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Ingénierie des Systèmes d'Information', semestre='9 ', description='null', nbhCm=20, nbhTd=20, nbhTp=20}, UniteEnseignement{id=UniteEnseignementId(codeFormation=M2DOSI, codeUe=DIDI)noEnseignantEnseignant{id=1, type='MCF', sexe='H', nom='S', prenom='P'}, codeFormation=Formation{id='M2DOSI', diplome='M', n0Annee=3, nomFormation='Master Développement à l'Offshore des Systèmes d'Information', doubleDiplome='O', debutAccreditation=2012-09-01, finAccreditation=2017-09-30}, designation='Ingénierie des Systèmes d'Information', semestre='9 ', description='null', nbhCm=30, nbhTd=30, nbhTp=30}]
但在我的邮递员中,有时它会给我 Object 有时一样长。
[
{
"id": {
"codeFormation": "M2DOSI",
"codeUe": "ISI"
},
"codeFormation": {
"id": "M2DOSI",
"diplome": "M",
"n0Annee": 3,
"nomFormation": "Master Développement à l'Offshore des Systèmes d'Information",
"doubleDiplome": "O",
"debutAccreditation": "01-09-2012",
"finAccreditation": "30-09-2017",
"debutAccreditationBeforeFinAccreditation": true
},
"noEnseignant": {
"id": 1,
"type": "MCF",
"sexe": "H",
"nom": "S",
"prenom": "P",
"adresse": "6 rue de l'eglise",
"codePostal": "29860",
"ville": "LE DRENNEC",
"pays": "FR",
"mobile": "06.00.00.01.00",
"telephone": "02.98.01.69.74",
"emailUbo": "[email protected]",
"emailPerso": "[email protected]"
},
"designation": "Ingénierie des Systèmes d'Information",
"semestre": "9 ",
"description": null,
"nbhCm": 30,
"nbhTd": 30,
"nbhTp": 30
},
{
"id": {
"codeFormation": "M2DOSI",
"codeUe": "IDL"
},
"codeFormation": {
"id": "M2DOSI",
"diplome": "M",
"n0Annee": 3,
"nomFormation": "Master Développement à l'Offshore des Systèmes d'Information",
"doubleDiplome": "O",
"debutAccreditation": "01-09-2012",
"finAccreditation": "30-09-2017",
"debutAccreditationBeforeFinAccreditation": true
},
"noEnseignant": 1,
"designation": "Ingénierie de Développement Logiciel",
"semestre": "9 ",
"description": null,
"nbhCm": 20,
"nbhTd": 20,
"nbhTp": 20
},
{
"id": {
"codeFormation": "M2DOSI",
"codeUe": "J2EE"
},
"codeFormation": {
"id": "M2DOSI",
"diplome": "M",
"n0Annee": 3,
"nomFormation": "Master Développement à l'Offshore des Systèmes d'Information",
"doubleDiplome": "O",
"debutAccreditation": "01-09-2012",
"finAccreditation": "30-09-2017",
"debutAccreditationBeforeFinAccreditation": true
},
"noEnseignant": {
"id": 2,
"type": "MCF",
"sexe": "H",
"nom": "LL",
"prenom": "MM",
"adresse": "18rue du pont",
"codePostal": "29200",
"ville": "BREST",
"pays": "FR",
"mobile": "06.00.00.00.32",
"telephone": "02.08.01.67.32",
"emailUbo": "[email protected]",
"emailPerso": "[email protected]"
},
"designation": "Java/J2EE",
"semestre": "9 ",
"description": null,
"nbhCm": 20,
"nbhTd": 20,
"nbhTp": 20
},
{
"id": {
"codeFormation": "M2DOSI",
"codeUe": "SR"
},
"codeFormation": {
"id": "M2DOSI",
"diplome": "M",
"n0Annee": 3,
"nomFormation": "Master Développement à l'Offshore des Systèmes d'Information",
"doubleDiplome": "O",
"debutAccreditation": "01-09-2012",
"finAccreditation": "30-09-2017",
"debutAccreditationBeforeFinAccreditation": true
},
"noEnseignant": 2,
"designation": "Systèmes Répartis",
"semestre": "10 ",
"description": null,
"nbhCm": 20,
"nbhTd": 20,
"nbhTp": 20
}
]
我想始终发送 noEnseignant 作为对象。
我尝试在循环中设置 noEnseignant,但我不认为这是服务问题,因为即使在我的控制器中它也能正确打印所有内容。
从实体 Enseignant 中删除它可以解决问题。
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")