@DynamicInsert
@DynamicUpdate
@Builder
@Entity
@Data //生成getter,setter等函数
@AllArgsConstructor //生成全参数构造函数
@NoArgsConstructor //生成无参构造函数
@SuppressWarnings("unused")//去除黄色警告
@Table(name = "cs_album")
public class CsAlbum {
// 主键ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(name = "id", value = "主键ID",hidden = true)
private Long id;
//用户id
@Column(nullable=false,name="uId",columnDefinition="bigint COMMENT '用户id'")
@ApiModelProperty(name = "uId", value = "用户id")
private Long uId;
@ManyToMany
@JoinTable(
//指定表名字
name = "cs_album_design_works",
//配置维护放字段
joinColumns = @JoinColumn(name = "album_id",referencedColumnName = "id"),
//配置被维护放字段
inverseJoinColumns = @JoinColumn(name = "design_works_id",referencedColumnName = "id")
)
private List<CsDesignWorks> csDesignWorks = new ArrayList<>( );
}
被维护表CsDesignWorks
@DynamicInsert
@DynamicUpdate
@Builder
@Entity
@Data //生成getter,setter等函数
@AllArgsConstructor //生成全参数构造函数
@NoArgsConstructor //生成无参构造函数
@SuppressWarnings("unused")//去除黄色警告
@Table(name = "cs_design_works")
public class CsDesignWorks {
// 主键ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ApiModelProperty(name = "id", value = "主键ID",hidden = true)
private Long id;
@ManyToMany(mappedBy = "csDesignWorks")
private List<CsAlbum> csAlbums = new ArrayList<>( );
}
Service类
@Service
@Transactional
public class CsAlbumServiceImpl implements CsAlbumService {
//根据id查询专辑内容
@Override
public CsAlbum viewAlbum(Long id){
CsAlbum csAlbum = csAlbumRepository.findById( id ).get();
csAlbum.getCsDesignWorks();
return csAlbum;
}
}
出现死循环为什么呢