|
1 | | -package com.hihat.blog.domain; |
2 | | - |
3 | | -import jakarta.persistence.*; |
4 | | -import lombok.AccessLevel; |
5 | | -import lombok.Builder; |
6 | | -import lombok.Getter; |
7 | | -import lombok.NoArgsConstructor; |
8 | | -import org.springframework.data.annotation.CreatedDate; |
9 | | -import org.springframework.data.annotation.LastModifiedDate; |
10 | | -import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
11 | | - |
12 | | -import java.time.LocalDateTime; |
13 | | - |
14 | | -@Table(name = "article") |
15 | | -@Entity // 엔티티 지정 |
16 | | -@Getter |
17 | | -@NoArgsConstructor(access = AccessLevel.PROTECTED) // protected 기본 생성자 |
18 | | -@EntityListeners(AuditingEntityListener.class) |
19 | | -public class Article { |
20 | | - |
21 | | - @Id |
22 | | - @GeneratedValue(strategy = GenerationType.IDENTITY) // Auto Increment |
23 | | - @Column(name ="id", updatable = false) |
24 | | - private Long id; |
25 | | - |
| 1 | +package com.hihat.blog.domain; |
| 2 | + |
| 3 | +import jakarta.persistence.*; |
| 4 | +import lombok.AccessLevel; |
| 5 | +import lombok.Builder; |
| 6 | +import lombok.Getter; |
| 7 | +import lombok.NoArgsConstructor; |
| 8 | +import org.springframework.data.annotation.CreatedDate; |
| 9 | +import org.springframework.data.annotation.LastModifiedDate; |
| 10 | +import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 11 | + |
| 12 | +import java.time.LocalDateTime; |
| 13 | + |
| 14 | +@Table(name = "article") |
| 15 | +@Entity // 엔티티 지정 |
| 16 | +@Getter |
| 17 | +@NoArgsConstructor(access = AccessLevel.PROTECTED) // protected 기본 생성자 |
| 18 | +@EntityListeners(AuditingEntityListener.class) |
| 19 | +public class Article { |
| 20 | + |
| 21 | + @Id |
| 22 | + @GeneratedValue(strategy = GenerationType.IDENTITY) // Auto Increment |
| 23 | + @Column(name ="id", updatable = false) |
| 24 | + private Long id; |
| 25 | + |
26 | 26 | @Column(name = "title", nullable = false) // Not Null |
27 | 27 | private String title; |
28 | 28 |
|
29 | | - @Column(name = "content" ,nullable = false) // Not Null |
| 29 | + @Lob |
| 30 | + @Column(name = "content", nullable = false, columnDefinition = "TEXT") // Not Null |
30 | 31 | private String content; |
31 | | - |
32 | | - @Column(name = "author", nullable = false) |
33 | | - private String author; |
34 | | - |
35 | | - @Column(name = "type", nullable = false) |
36 | | - private String type; |
37 | | - |
38 | | - @CreatedDate |
39 | | - @Column(name = "created_at") |
40 | | - private LocalDateTime createdAt; |
41 | | - |
42 | | - @LastModifiedDate |
43 | | - @Column(name = "updated_at") |
44 | | - private LocalDateTime updatedAt; |
45 | | - |
46 | | - @Builder // 빌더 패턴으로 객체 생성 |
47 | | - public Article(String title, String content, String author, String type) { |
48 | | - this.title = title; |
49 | | - this.content = content; |
50 | | - this.author = author; |
51 | | - this.type = type; |
52 | | - } |
53 | | - |
54 | | - // 수정 메서드 |
55 | | - public void update(String title, String content, String type) { |
56 | | - this.title = title; |
57 | | - this.content = content; |
58 | | - this.type = type; |
59 | | - } |
60 | | -} |
| 32 | + |
| 33 | + @Column(name = "author", nullable = false) |
| 34 | + private String author; |
| 35 | + |
| 36 | + @Column(name = "type", nullable = false) |
| 37 | + private String type; |
| 38 | + |
| 39 | + @CreatedDate |
| 40 | + @Column(name = "created_at") |
| 41 | + private LocalDateTime createdAt; |
| 42 | + |
| 43 | + @LastModifiedDate |
| 44 | + @Column(name = "updated_at") |
| 45 | + private LocalDateTime updatedAt; |
| 46 | + |
| 47 | + @Builder // 빌더 패턴으로 객체 생성 |
| 48 | + public Article(String title, String content, String author, String type) { |
| 49 | + this.title = title; |
| 50 | + this.content = content; |
| 51 | + this.author = author; |
| 52 | + this.type = type; |
| 53 | + } |
| 54 | + |
| 55 | + // 수정 메서드 |
| 56 | + public void update(String title, String content, String type) { |
| 57 | + this.title = title; |
| 58 | + this.content = content; |
| 59 | + this.type = type; |
| 60 | + } |
| 61 | +} |
0 commit comments