1. 여러 곳에서 공통으로 사용할 수 있는 파일 엔티티
- 각 테이블 별로 관리하지 않고
- parentTable과 parentNo로 소속 테이블과 관련된 문서 번호를 관리
2. FileEntity.java (File로 작성 시 이름 충돌이 자주 발생 가능성 존재!!)
package kitae.spring.project.file.entity;
import jakarta.persistence.*;
import kitae.spring.project.common.entity.BaseEntity;
import lombok.*;
@Entity
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class FileEntity extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "file_id", nullable = false)
private Long id; // 아이디
@Column(length = 45, nullable = false)
private String parentTable; // 부모 테이블명
@Column(nullable = false)
private Long parentNo; // 부모 테이블의 PK
@Enumerated(EnumType.STRING)
@Column(nullable = false, columnDefinition = "VARCHAR(10) DEFAULT 'SUB'")
private FileType type; // 파일 타입("MAIN", "SUB")
@Column(nullable = false)
private String fileName; // 저장 파일명
@Column(nullable = false)
private String originName; // 원본 파일명
@Column(nullable = false)
private String filePath; // 파일 경로
@Column(nullable = false, columnDefinition = "BIGINT DEFAULT 0")
private Long fileSize; // 파일 크기
@Column(nullable = false)
private Long seq = 0L; // 순서
}
3. FileType.java (열거형)
public enum FileType {
MAIN, SUB
}