|
| 1 | +package com.example.crud.model; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| 4 | +import org.springframework.data.annotation.CreatedDate; |
| 5 | +import org.springframework.data.annotation.LastModifiedDate; |
| 6 | +import org.springframework.data.jpa.domain.support.AuditingEntityListener; |
| 7 | + |
| 8 | +import javax.persistence.*; |
| 9 | +import javax.validation.constraints.NotBlank; |
| 10 | +import java.util.Date; |
| 11 | + |
| 12 | +@Entity |
| 13 | +@Table(name = "Coalas") |
| 14 | +@EntityListeners(AuditingEntityListener.class) |
| 15 | +@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, |
| 16 | + allowGetters = true) |
| 17 | +public class Coala { |
| 18 | + @Id |
| 19 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
| 20 | + private Long id; |
| 21 | + |
| 22 | + @NotBlank |
| 23 | + private String title; |
| 24 | + |
| 25 | + @NotBlank |
| 26 | + private String content; |
| 27 | + |
| 28 | + @Column(nullable = false, updatable = false) |
| 29 | + @Temporal(TemporalType.TIMESTAMP) |
| 30 | + @CreatedDate |
| 31 | + private Date createdAt; |
| 32 | + |
| 33 | + @Column(nullable = false) |
| 34 | + @Temporal(TemporalType.TIMESTAMP) |
| 35 | + @LastModifiedDate |
| 36 | + private Date updatedAt; |
| 37 | + |
| 38 | + public Long getId() { |
| 39 | + return id; |
| 40 | + } |
| 41 | + |
| 42 | + public void setId(Long id) { |
| 43 | + this.id = id; |
| 44 | + } |
| 45 | + |
| 46 | + public String getTitle() { |
| 47 | + return title; |
| 48 | + } |
| 49 | + |
| 50 | + public void setTitle(String title) { |
| 51 | + this.title = title; |
| 52 | + } |
| 53 | + |
| 54 | + public String getContent() { |
| 55 | + return content; |
| 56 | + } |
| 57 | + |
| 58 | + public void setContent(String content) { |
| 59 | + this.content = content; |
| 60 | + } |
| 61 | + |
| 62 | + public Date getCreatedAt() { |
| 63 | + return createdAt; |
| 64 | + } |
| 65 | + |
| 66 | + public void setCreatedAt(Date createdAt) { |
| 67 | + this.createdAt = createdAt; |
| 68 | + } |
| 69 | + |
| 70 | + public Date getUpdatedAt() { |
| 71 | + return updatedAt; |
| 72 | + } |
| 73 | + |
| 74 | + public void setUpdatedAt(Date updatedAt) { |
| 75 | + this.updatedAt = updatedAt; |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments