我对一对多的关系有问题,我只想使用用户 ID 我不想创建一个新的,我把我的代码
@PostMapping("/createFavorite")
public ResponseEntity<Favorite> createFavorite(@RequestBody Favorite favorite) {
return new ResponseEntity<Favorite>(userServiceImpl.createFavorite(favorite), HttpStatus.OK);
}
我最喜欢的实体是
public class Favorite implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "element")
private String element;
@ManyToOne
@JoinColumn(name = "user_fk")
User user;
我大摇大摆地明白了
{
"element": "string",
"user": {
"email": "string",
"id": 0,
"life": "suspend",
"name": "string",
"password": "string"
}
}
我不想创建新用户,用户已经创建,我只需要使用您的 ID 来引用它
明月笑刀无情
www说
12345678_0001
相关分类