user entity

This commit is contained in:
jinho jeong
2022-04-20 15:41:14 +09:00
parent 390fdba0cd
commit 0ba0e948db
3 changed files with 111 additions and 33 deletions

View File

@@ -0,0 +1,23 @@
package com.example.oneul.model;
import java.time.LocalDateTime;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.springframework.data.annotation.CreatedDate;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@NoArgsConstructor
@Entity
public class Post {
@Id @GeneratedValue
private Long id;
@CreatedDate
private LocalDateTime createdAt;
private String content;
}

View File

@@ -1,33 +0,0 @@
package com.example.oneul.model;
import java.time.LocalDate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class User {
@Id @GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
private String password;
private LocalDate createdAt;
public Long getId(){
return this.id;
}
public String getUsername(){
return this.username;
}
public String getPassword(){
return this.password;
}
public LocalDate getCreatedAt(){
return this.createdAt;
}
}

View File

@@ -0,0 +1,88 @@
package com.example.oneul.model;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.springframework.data.annotation.CreatedDate;
@Entity
public class UserEntity {
@Id @GeneratedValue
private Long id;
@Column(nullable = false)
private String username;
@Column(nullable = false)
private String password;
@CreatedDate
private LocalDateTime createdAt;
public Long getId(){
return this.id;
}
public String getUsername(){
return this.username;
}
public String getPassword(){
return this.password;
}
public LocalDateTime getCreatedAt(){
return this.createdAt;
}
public UserEntity(Long id, String username, String password, LocalDateTime createdAt){
this.id = id;
this.username = username;
this.password = password;
this.createdAt = createdAt;
}
@Override
public String toString(){
return "userEntity["
+ "id: " + this.id
+ ", username: " + this.username
+ ", createdAt: " + this.createdAt
+ "]";
}
public static class Builder {
private Long id;
private String username;
private String password;
private LocalDateTime createdAt;
public UserEntity build() {
return new UserEntity(
id,
username,
password,
createdAt);
}
public Builder id(Long id){
this.id = id;
return this;
}
public Builder username(String username){
this.username = username;
return this;
}
public Builder password(String password){
this.password = password;
return this;
}
public Builder createdAt(LocalDateTime createdAt){
this.createdAt = createdAt;
return this;
}
}
}