[Spring] CRUD 기능 구현

Oublie-le·2024년 9월 6일

스프링(게시판)

목록 보기
1/3

Spring 김영한 입문 강의를 복습하는 겸 스프링부트를 이용해 게시판을 만들어 보려고 한다.

1.기능

-Create 글 작성
-Read 글 보기(글 목록, 글 전문)
-Update 글 수정
-Delete 글 삭제
(글 수정과 삭제는 비밀번호가 일치한 경우에만 가능)

2.프로젝트 구조


-domain:비즈니스 도메인 객체
-content 객체 생성
-repository:DB와 연결되는 부분
(현재는 DB와 연결하지 않았기 때문에 Map을 사용해 데이터 저장)
-service:핵심 비즈니스 로직
-controller : 웹 mvc에서 컨트롤러 역할
-url mapping, view return, service와 연결

3.구현코드

3.1 사용 라이브러리

spring-boot-starter-web
spring-boot-starter-thymeleaf
spring-boot-devtools
lombok
spring-boot-starter-test

3.2 domain>Content

-Content 객체
-Content(게시글)에는 각각 id, title,writer, updateDate,texts,password, tag가 필요

3.3 repository>ContentRepository

-contents라는 Map을 생성 후 사용
-contents에 저장, 수정, 삭제, 조회하는 기능 담당(CRUD)

3.4 service>ContentService

-핵짐 비즈니스 로직
-Controller, Repository와 연결되어 데이터 송/수신

3.5 controller > ContentController

-모든 화면들은 mapping하는 컨트롤러
-view, service와 연결되어 데이터 송/수신

3.6 static>newstyle.css

-전체 레이아웃 디자인

3.7 templates>home2.html

-홈화면이자 글목록 화면

3.8 templates>write-page

-글쓰기화면

3.9 templates>content-page

-글 보기 화면
-글 내용 수정 기능
-글 삭제 기능
-수정, 삭제 시 비밀번호 확인 창에 입력한 비밀번호가 일치해야 작동

4.결과

4.1 홈 화면

4.2 글 쓰기 화면

4.3 글 보기 화면

4.4 글이 수정된 화면

profile
개발자 지망생

0개의 댓글