我有3个实体:
SLUSER_INFO(SLUSER_INFO_ID, FULLNAME, FIRSTNAME, LASTNAME, ADDRESS, DOB)
SLUSER(SLUSER_ID, PASSWORD, USERNAME, SLUSER_INFO_ID)
SLROLE(SLROLE_ID, ROLENAME, SLUSER_ID)
在用户实体中:
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonView(SlUserView.Full.class)
private List<SlRole> roles;
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "SLUSER_INFO_ID", referencedColumnName = "SLUSER_INFO_ID")
@JsonView(SlUserView.Full.class)
private SlUserInfo userInfo;
在角色实体中:
@ManyToOne
@JoinColumn(name = "SLUSER_ID", referencedColumnName = "SLUSER_ID")
private SlUser user;
和User_info实体
@OneToOne(mappedBy = "userInfo")
private SlUser user;
我通过使用JPARepository findAll
创建其余的api以获取所有用户@Repository
public interface SlUserRepository extends JpaRepository<SlUser, Long> {
}
控制器
public ResponseEntity<Page<SlUser>> findAll(Pageable pageable) {
Page<SlUser> pageResult = usersRepository.findAll(pageable);
return new ResponseEntity<Page<SlUser>>(pageResult, HttpStatus.OK);
}
尝试运行其余的api,结果是重复的数据。
{&#34;内容&#34;:[{&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&# 34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34 ;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34 ;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34 ; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34 ;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34 ;, &#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34 ;, &#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:& #34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;,& #34;的firstName&#34;:&#34; Jayce&#34;&#34 ; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&# 34;:{&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34; &#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34 ;:{&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34 ;, &#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34 ;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理与#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&# 34;,&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空, &#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&# 34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],& #34; USERINFO&#34; {&#34; ID&#34 ;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:& #34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34 ; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&# 34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34 ;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34;:{ &#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34 ;角色&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34;:{& #34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34 ;:{&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34 ;, &#34;作用&#34;:[{&#34; ID&# 34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34 ;, &#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1, &#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34 ; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,& #34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&# 34;,&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34; :1,&#34;用户名&#34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{ &#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34 ;: 1,&#34;全名&#34;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34 ;声纳&#34;&#34;地址&#34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID& #34;:1,&#34;用户名&#34;:&#34 ; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34; &#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34 ;: &#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34 ;: &#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,& #34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:& #34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&# 34;:&#34; AD1&#34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&# 34;:&#34; v7001&#34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34 ;: 1,&#34; ROLENAME&#34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34 ;:&#34;&#34;&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34 ;地址&#34;:&#34; AD1&#34; &#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001&#34; &#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&#34 ;: &#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&#34 ;, &#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&#34; AD1& #34;&#34; DOB&#34;:空,&#34;使用者&#34; {&#34; ID&#34;:1,&#34;用户名&#34;:&#34; v7001& #34;&#34;密码&#34;:&#34;管理&#34;&#34;作用&#34;:[{&#34; ID&#34;:1,&#34; ROLENAME&# 34;:&#34; ADMIN&#34;}],&#34; USERINFO&#34; {&#34; ID&#34;:1,&#34;全名&#34;:&#34;&# 34;,&#34;的firstName&#34;:&#34; Jayce&#34;&#34; lastName的&#34;:&#34;声纳&#34;&#34;地址&#34;:&# 34; AD1&#34;&#34; DOB&#34;:空,&#34;用户&#34;:
请给我建议
答案 0 :(得分:0)
错误是由于User
和Roles
之间的双向关系造成的。
在@JsonIgnore
实体的roles
上使用User
。