jpablog : create entity
This commit is contained in:
43
jpablog/src/main/java/com/example/jpablog/model/Board.java
Normal file
43
jpablog/src/main/java/com/example/jpablog/model/Board.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package com.example.jpablog.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
public class Board {
|
||||||
|
|
||||||
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 100)
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Lob // 대용량 데이터
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@ColumnDefault("0")
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
@ManyToOne(fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "user_id")
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@OneToMany(mappedBy = "board")
|
||||||
|
private List<Reply> reply = new ArrayList<>();
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private LocalDateTime createDate;
|
||||||
|
}
|
||||||
35
jpablog/src/main/java/com/example/jpablog/model/Reply.java
Normal file
35
jpablog/src/main/java/com/example/jpablog/model/Reply.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package com.example.jpablog.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
public class Reply {
|
||||||
|
|
||||||
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 200)
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "board_id")
|
||||||
|
private Board board;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "user_id")
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private LocalDateTime createDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.example.jpablog.model;
|
||||||
|
|
||||||
|
public enum Role {
|
||||||
|
ADMIN, USER, MANAGER
|
||||||
|
}
|
||||||
38
jpablog/src/main/java/com/example/jpablog/model/User.java
Normal file
38
jpablog/src/main/java/com/example/jpablog/model/User.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package com.example.jpablog.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.hibernate.annotations.ColumnDefault;
|
||||||
|
import org.hibernate.annotations.CreationTimestamp;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Builder
|
||||||
|
@Entity
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) // 프로젝트 에서 연결된 DB의 넘버링 전략 사용
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 30)
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 100)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@Column(nullable = false, length = 50)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@ColumnDefault("'USER'")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private Role role;
|
||||||
|
|
||||||
|
@CreationTimestamp
|
||||||
|
private LocalDateTime createDate;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.example.jpablog.test;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class ControllerTest {
|
||||||
|
|
||||||
|
@GetMapping("/temp/home")
|
||||||
|
public String tempHome() {
|
||||||
|
// 파일 리턴 기본경로 : src/main/resources/static
|
||||||
|
return "/home.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/temp/jsp")
|
||||||
|
public String tempJsp() {
|
||||||
|
return "/test";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.example.jpablog.test;
|
package com.example.jpablog.test;
|
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class HttpControllerTest {
|
public class RestControllerTest {
|
||||||
|
|
||||||
@GetMapping("/http/get")
|
@GetMapping("/http/get")
|
||||||
public String getTest(Member member) {
|
public String getTest(Member member) {
|
||||||
@@ -15,8 +16,8 @@ public class HttpControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/http/post")
|
@PostMapping("/http/post")
|
||||||
public String postTest() {
|
public ResponseEntity<Member> postTest(@RequestBody Member member) {
|
||||||
return "post 요청";
|
return new ResponseEntity<>(member, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/http/put")
|
@PutMapping("/http/put")
|
||||||
@@ -1,6 +1,35 @@
|
|||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
servlet:
|
||||||
|
context-path: /jpablog
|
||||||
|
encoding:
|
||||||
|
charset: UTF-8
|
||||||
|
enabled: true
|
||||||
|
force: true
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
mvc:
|
||||||
|
view:
|
||||||
|
prefix: /WEB-INF/views/
|
||||||
|
suffix: .jsp
|
||||||
|
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Seoul
|
url: jdbc:mysql://localhost:3306/jpablog?serverTimezone=Asia/Seoul
|
||||||
username: jpablog
|
username: jpablog
|
||||||
password: 1234
|
password: 1234
|
||||||
|
|
||||||
|
jpa:
|
||||||
|
open-in-view: true
|
||||||
|
hibernate:
|
||||||
|
ddl-auto: create
|
||||||
|
# naming:
|
||||||
|
# physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
|
||||||
|
use-new-id-generator-mappings: false
|
||||||
|
show-sql: true
|
||||||
|
properties:
|
||||||
|
hibernate.format_sql: true
|
||||||
|
|
||||||
|
jackson:
|
||||||
|
serialization:
|
||||||
|
fail-on-empty-beans: false
|
||||||
10
jpablog/src/main/resources/static/home.html
Normal file
10
jpablog/src/main/resources/static/home.html
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Title</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>home.html</h1>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
1
jpablog/src/main/webapp/WEB-INF/views/test.jsp
Normal file
1
jpablog/src/main/webapp/WEB-INF/views/test.jsp
Normal file
@@ -0,0 +1 @@
|
|||||||
|
hello
|
||||||
Reference in New Issue
Block a user