在我的 Spring BOOT 应用程序中,我有一个User
类和一个LoginCreadential
类。
在我的User
班上,我有:
@OneToOne(fetch = FetchType.LAZY,targetEntity = LoginCredential.class)
@JoinColumn(name = "userID",referencedColumnName = "userID")
@JsonIgnore
private LoginCredential loginCredential;
在我的LoginCraedential
班上:
@OneToOne(mappedBy = "loginCredential", fetch = FetchType.LAZY)
User user;
当我通过这样的 React.js 应用程序创建LoginCreadential
时:
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://localhost:8080/login/');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify({ email: this.state.email,passwordHash:this.state.passwordHash }));
我得到这样的东西:
{"userID":65,"passwordHash":"sad","user":null,"email":"aszzzzzzzzzzdasdasd"},
我的LoginCreadential
类具有两个构造函数:
LoginCredential()
{
}
public LoginCredential(String eMail, String passwordHash,User user)
{
this.eMail=eMail;
this.passwordHash=passwordHash;
this.user=user;
}
在我的LoginCredentialController
班上,我有:
@PostMapping("/login")
void newLoginCredential(@RequestBody LoginCredential newLoginCredential)
{
List<LoginCredential> userList=repository.findByEmailAddress(newLoginCredential.getEMail());
if(userList==null || userList.size()==0)
repository.save(newLoginCredential);
}
用户始终为null,是否应该创建一个空的User
或类似的东西?
如果没有,我怎么能做到?