.gitignore 운영체제에 맞게 쓰고 싶으면
https://www.toptal.com/developers/gitignore 여기로 들어가서 제외목록 넣기
코드를 복사후 -> EOF 관련해서 맨 밑줄 한칸 띄우고 맨 윗줄 공백 없애기
@EnableJpaAuditing
@Configuration
public class JpaConfig {
@Bean
public AuditorAware<String> auditorAware(){
return () -> Optional.of("uno"); //Todo 스프링 시큐리티로 인증 기능을 붙이게 될 때
}
}
@CreatedDate
private LocalDateTime createdAt;
@CreatedBy
private String createdBy;
@LastModifiedDate
private LocalDateTime modifiedAt;
@LastModifiedBy
private String modifiedBy;
이렇게 선언하면 엔티티로 변환하거나 저장할때 따로 값을 않넣어줘도 자동으러 넣게 돼 ㅁ
@EntityListeners(AuditingEntityListener.class) << entity 위에 반드시 들어가야 auding이 적용됨 여기까지 해야되는거
객체지향적으로 db만들기
ArtilcleCommentEntity 에 들어갈 내용
@ManyToOne(optional = false)
private ArticleEntity article;
이거는 필수값이다 라는 뜼
ArtilceEntity 에 들어갈 내용
@ToString.Exclude //이게 있어야 순환참조 끊을 수 있음
@OrderBy("id")
@OneToMany(mappedBy="article", cascade = CascadeType.ALL)
완성본
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "article")
public class ArticleEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 255)
private String title;
@Column(nullable = false, length = 10000)
private String content;
@Column(nullable = false, length = 255)
private String hashtag;
@CreatedDate
@Column(nullable = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime createdAt;
@CreatedBy
@Column(nullable = false, length = 100)
private String createdBy;
@LastModifiedDate
@Column(nullable = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime modifiedAt;
@LastModifiedBy
@Column(nullable = false, length = 100)
private String modifiedBy;
@ToString.Exclude
@OrderBy("id")
@OneToMany(mappedBy="article", cascade = CascadeType.ALL)
private final List<ArticleCommentEntity> articleComments = new ArrayList<>();
}
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EntityListeners(AuditingEntityListener.class)
@Entity
@Table(name = "article_comment")
public class ArticleCommentEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(optional = false)
private ArticleEntity article;
@Column(nullable = false, length = 10000)
private String content;
@CreatedDate
@Column(nullable = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime createdAt;
@CreatedBy
@Column(nullable = false, length = 100)
private String createdBy;
@LastModifiedDate
@Column(nullable = false )
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private LocalDateTime modifiedAt;
@LastModifiedBy
@Column(nullable = false, length = 100)
private String modifiedBy;
private final List<ArticleCommentEntity> articleComments = new ArrayList<>();
JAVA/게시판 프로젝트