Spring MVC ๊ฐ„๋‹จํ•œ ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ

2021. 11. 29. 14:25ใ†Spring

728x90

๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณด๊ณ ,

์˜ˆ์ „์— jsp๊ณต๋ถ€ํ•  ๋•Œ ๋งŒ๋“ค์—ˆ๋˜ jdbc ๊ฒŒ์‹œํŒ์„ ์‘์šฉํ•ด 

Spring MVC ๋ฒ„์ „์œผ๋กœ ๊ฒŒ์‹œํŒ์„ ๋งŒ๋“ค์–ด๋ณผ ์˜ˆ์ •์ด๋‹ค. 

์ตœ์ข… ๊ฒฐ๊ณผ ํ™”๋ฉด์œผ๋กœ 

๊ธ€ ์ž‘์„ฑ, ์ˆ˜์ •, ์‚ญ์ œ, ์กฐํšŒ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๊ฒŒ์‹œํŒ์„ ๋งŒ๋“ค์–ด๋ณผ ์˜ˆ์ •์ด๋‹ค. 

 

Board ํ…Œ์ด๋ธ” 

board_seq ์‹œํ€€์Šค๋ฅผ ์ƒ์„ฑํ•ด ๊ฒŒ์‹œ๊ธ€์„ ์ž‘์„ฑํ•  ๋•Œ๋งˆ๋‹ค ์ž๋™์œผ๋กœ 1์”ฉ wr_uid๊ฐ€ ์ฆ๊ฐ€ํ•˜๋„๋ก ํ–ˆ๋‹ค.

๊ธฐ๋ณธํ‚ค๋Š” wr_uid

 

0๏ธโƒฃ MVC ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ 

new - > Spring legacy project -> Spring mvc project 
ํŒจํ‚ค์ง€๋ช… ์„ค์ • 

โ— ํŒจํ‚ค์ง€๋ช… ์ž‘์„ฑํ•  ๋•Œ๋Š” ์˜ˆ๋ฅผ ๋“ค์–ด com.lec.board๋‹ค ํ•˜๋ฉด ๋งˆ์ง€๋ง‰ ์„ธ๋ฒˆ์งธ ์ฆ‰ board๊ฐ€ ์ปจํ…์ŠคํŠธ ์ด๋ฆ„์ด ๋˜๊ธฐ ๋•Œ๋ฌธ์— 

์„ค์ • ์ž˜ํ•ด์ฃผ๊ธฐ!

 

์ด๋Ÿฐ์‹์˜ Sping MVC ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ์„ฑ๋˜์—ˆ๋‹ค๋ฉด 

src/main/java๋Š” ์›น root 

servlet-context.xml์€ ์Šคํ”„๋ง ์„ค์ •ํŒŒ์ผ 

web.xml์€ dispatcherServlet ์„ค์ •ํŒŒ์ผ๋กœ, servlet-context.xml ํŒŒ์ผ ์œ„์น˜๋„ ์ •์˜ํ•ด๋‘”๋‹ค.

pom.xml์—๋Š” maven ์„ค์ •ํŒŒ์ผ์ด๋‹ค.

 

 

1๏ธโƒฃ pom.xml, web.xml ์„ค์ •ํŒŒ์ผ 

pom.xml์—๋Š” ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•ด์ฃผ๊ณ , web.xml์—๋Š” ํ•œ๊ธ€ ์ธ์ฝ”๋”ฉ ์ฝ”๋“œ๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๊ธ€์ด ๊นจ์ง€์ง€ ์•Š๋Š”๋‹ค.

<!-- ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ ์ธ์ฝ”๋”ฉ ์„ค์ • --> <filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

web.xml์— ๋ณต๋ถ™ํ•˜๊ณ  ์ €์žฅํ•˜๋ฉด ๋œ๋‹ค. 

pom.xml์—๋Š” ์ž์‹ ์˜ ๋ฒ„์ „์— ๋งž๊ฒŒ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. 

<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.0.Final</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.17.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-aop -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.2.17.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.5</version>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc6 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.2.17.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.annotation/javax.annotation-api -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.2.17.RELEASE</version>
<scope>test</scope>
</dependency>

 

๋‚ด๊ฐ€ ์ถ”๊ฐ€ํ–ˆ๋˜ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์ด๋ ‡๊ฒŒ ๋œ๋‹ค!

 

 

2๏ธโƒฃ ํ•„์š”ํ•œ ํŒจํ‚ค์ง€, ํด๋ž˜์Šค, jsp ์ƒ์„ฑํ•˜๊ธฐ 

value.properties ์ƒ์„ฑ

 

 

3๏ธโƒฃ Spring ์„ค์ • ํŒŒ์ผ 

Spring ์„ค์ • ํŒŒ์ผ์ธ servlet-context.xml์— dataSource์™€ mybatis ๋“ฑ์˜ ๋นˆ์„ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค. 

dataSource ์„ค์ • 
MyBatis ์„ค์ • 
Mapper ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • 

โ— Mapper ์ธํ„ฐํŽ˜์ด์Šค

: Mapping ํŒŒ์ผ์— ๊ธฐ์žฌ๋œ sql์„ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค๋กœ Mapping ํŒŒ์ผ์— ์žˆ๋Š” sql์„ ์ž๋ฐ” ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ†ตํ•ด ํ˜ธ์ถœ ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค. 

 

 

4๏ธโƒฃ MyBatis ์„ค์ • ํŒŒ์ผ ์ž‘์„ฑํ•˜๊ธฐ(Vo๊ฐ์ฒด์„ค์ •) SqlMapConfig.xml , Mapping ํŒŒ์ผ ์ž‘์„ฑ Board.xml 

SqlMapConfig.xml
board.xml

 

5๏ธโƒฃ BoardVO, BoardService, BoardDAO ์ž‘์„ฑ ๋ฐ ๊ตฌํ˜„ํ•˜๊ธฐ 

 

- BoardVO.java

package com.lec.board.vo;

public class BoardVO {

	private int wr_uid;
	private String subject;
	private String content;
	private String name;
	private int viewcnt;
	private String regdate;
	
	public BoardVO() {
		super();
	}

	public BoardVO(int wr_uid, String subject, String content, String name, int viewcnt, String regdate) {
		super();
		this.wr_uid = wr_uid;
		this.subject = subject;
		this.content = content;
		this.name = name;
		this.viewcnt = viewcnt;
		this.regdate = regdate;
	}

	public int getWr_uid() {
		return wr_uid;
	}

	public void setWr_uid(int wr_uid) {
		this.wr_uid = wr_uid;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getViewcnt() {
		return viewcnt;
	}

	public void setViewcnt(int viewcnt) {
		this.viewcnt = viewcnt;
	}

	public String getRegdate() {
		return regdate;
	}

	public void setRegdate(String regdate) {
		this.regdate = regdate;
	}
	
	
	
}

๋ณ€์ˆ˜๋ช…์€ db ํ…Œ์ด๋ธ” ์ปฌ๋Ÿผ๋ช…๊ณผ ๋งž์ถฐ์ค€๋‹ค. 

 

- BoardService.java (์ธํ„ฐํŽ˜์ด์Šค)

package com.lec.board.service;

import java.util.List;

import com.lec.board.vo.BoardVO;

public interface BoardService {

	public List<BoardVO> selectList();
	
	public BoardVO selectOne(String wr_uid);
	
	public void updateViewcnt(String wr_uid);
	
	public void insertOne(BoardVO board);
	
	public void updateOne(BoardVO board);
	
	public void deleteOne(String wr_uid);
}

 

- BoardServiceImple.java (BoardService ๊ตฌํ˜„)

package com.lec.board.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lec.board.dao.BoardDAO;
import com.lec.board.vo.BoardVO;

@Service("boardService")
public class BoardServiceImple implements BoardService {

	@Autowired
	BoardDAO boardDao;
	
	@Override
	public List<BoardVO> selectList() {
		List<BoardVO> list = boardDao.selectAll();
		return list;
	}

	@Override
	public BoardVO selectOne(String wr_uid) {
		BoardVO board = boardDao.select(wr_uid);
		return board;
	}

	@Override
	public void updateViewcnt(String wr_uid) {
		boardDao.updateCount(wr_uid);
	}

	@Override
	public void insertOne(BoardVO board) {
		boardDao.insert(board);
	}

	@Override
	public void updateOne(BoardVO board) {
		boardDao.update(board);
	}

	@Override
	public void deleteOne(String wr_uid) {
		boardDao.delete(wr_uid);
	}

}

 

- BoardDAO.java (์ธํ„ฐํŽ˜์ด์Šค)

package com.lec.board.dao;

import java.util.List;

import com.lec.board.vo.BoardVO;

public interface BoardDAO {

	public List<BoardVO> selectAll();
	
	public BoardVO select(String wr_uid);
	
	public void updateCount(String wr_uid);
	
	public void insert(BoardVO board);
	
	public void update(BoardVO board);
	
	public void delete(String wr_uid);
}

 

- BoardDAOJDBC.java (BoardDAO ๊ตฌํ˜„)

package com.lec.board.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lec.board.vo.BoardVO;

@Repository("boardDao")
public class BoardDAOJDBC implements BoardDAO {

	@Autowired
	BoardMapper boardMapper;
	
	@Override
	public List<BoardVO> selectAll() {
		List<BoardVO> list = boardMapper.selectAll();
		return list;
	}

	@Override
	public BoardVO select(String wr_uid) {
		BoardVO board = boardMapper.selectOne(wr_uid);
		return board;
	}

	
	@Override
	public void updateCount(String wr_uid) {
		boardMapper.updateViewcnt(wr_uid);
	}

	@Override
	public void insert(BoardVO board) {
		boardMapper.insertOne(board);
	}

	@Override
	public void update(BoardVO board) {
		boardMapper.updateOne(board);
	}

	@Override
	public void delete(String wr_uid) {
		boardMapper.deleteOne(wr_uid);
	}


}

 

- BoardMapper ์ธํ„ฐํŽ˜์ด์Šค 

package com.lec.board.dao;

import java.util.List;

import com.lec.board.vo.BoardVO;

public interface BoardMapper {

	List<BoardVO> selectAll();
	
	BoardVO selectOne(String wr_uid);
	
	void insertOne(BoardVO board);
	
	void updateOne(BoardVO board);
	
	void deleteOne(String wr_uid);
	
	void updateViewcnt(String wr_uid);
}

 

โ— Spring MVC ๊ธฐ๋ฐ˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ž‘์„ฑ ์ ˆ์ฐจ 

1. ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›๋Š” DispatcherServlet๋ฅผ web.xml์— ์„ค์ •
2. ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  Controller ์ž‘์„ฑ
3. Spring bean์œผ๋กœ Controller ๋“ฑ๋ก 
4. jsp๋ฅผ ์ด์šฉํ•œ view ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ
5. browser ์ƒ์—์„œ jsp๋ฅผ ์‹คํ–‰ 

 

6๏ธโƒฃ ๊ฒŒ์‹œํŒ ๊ธ€ ๋ชฉ๋ก ์กฐํšŒ 

list.do

- BoardController

BoardController.java

๊ฒŒ์‹œํŒ ๋ชฉ๋ก ์กฐํšŒ ์š”์ฒญ url์€ "/board/list.do"์ด๋‹ค.

DispathcherServlet์ด ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์•„ url๊ณผ ์š”์ฒญ ์ •๋ณด๋ฅผ ๊ธฐ์ค€์œผ๋กœ HandlerMapping์„ ํ†ตํ•ด ๋ชจ๋ธ ๊ฐ์ฒด ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๋ชจ๋ธ์—์„œ ์š”์ฒญ์— ๋Œ€ํ•ด ์ฒ˜๋ฆฌํ•˜๊ณ , ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ๋ฐ์ดํ„ฐ๋ฅผ model์— ๋‹ด์•„ board/list.jsp ์— ๋ฆฌํ„ดํ•œ๋‹ค. 

list.jsp

list.jsp์—์„œ๋Š” ์ „๋‹ฌ๋ฐ›์€ ๊ฐ์ฒด๋ฅผ ${list}๋กœ ๋ฐ›์•„์„œ jstl core ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ํ…Œ์ด๋ธ”์— ๋ชฉ๋ก์„ ์ถœ๋ ฅํ•ด์ค€๋‹ค. 

๊ทธ๋ฆฌ๊ณ  ์ œ๋ชฉ์„ ํด๋ฆญํ•˜๋ฉด ํ•ด๋‹น ๊ธ€์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์ดํผ๋งํฌ๋ฅผ ๋‹ฌ์•˜๋‹ค. 

 

7๏ธโƒฃ ํŠน์ • ๊ธ€ ์กฐํšŒ

ํŠน์ • ๊ธ€ ์กฐํšŒ ๊ฒฐ๊ณผ 
BoardController.java

ํŠน์ • ๊ธ€ ์กฐํšŒ ์š”์ฒญ url์€ "/board/view.do"์ด๋‹ค. 

๊ทธ๋ฆฌ๊ณ  ํŠน์ • ๊ธ€ ์กฐํšŒ๋ฅผ ์œ„ํ•ด wr_uid ๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋Š”๋‹ค. 

ํŠน์ • ๊ธ€์„ ํด๋ฆญํ•˜๋ฉด ํ•ด๋‹น ๊ธ€์„ ์กฐํšŒํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•˜๋ฉฐ, ์กฐํšŒ์ˆ˜๊ฐ€ 1 ์ฆ๊ฐ€ํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— 

๋‘๊ฐ€์ง€๋ฅผ ์ˆ˜ํ–‰ํ•œ๋‹ค. 

๊ทธ๋ฆฌ๊ณ  ๋ชจ๋ธ์˜ ์ˆ˜ํ–‰ ๊ฒฐ๊ณผ๋ฅผ ModelAndView ๊ฐ์ฒด์— ๋ฐ˜ํ™˜ํ–ˆ๋‹ค. 

view.jsp

์กฐํšŒ ๊ฒฐ๊ณผ๋ฅผ board์— ๋‹ด์•„์„œ view.jsp์— ์ „๋‹ฌํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— view์—์„œ๋Š” ${board.wr_uid} ํ•˜๋ฉด ํ•ด๋‹น ๊ฐ’์„ ์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค. 

๊ทธ๋ฆฌ๊ณ  ํ•ด๋‹น ๊ธ€์„ ์‚ญ์ œํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ญ์ œํ•˜๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์‚ฌ์šฉ์ž์—๊ฒŒ ํ•œ๋ฒˆ ๋” ํ™•์ธํ•˜๋Š” ํ™•์ธ์ฐฝ์„ ๋„์›Œ ์‚ฌ์šฉ์ž๊ฐ€ ํ™•์ธ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ์•ผ ์‚ญ์ œ๊ฐ€ ๋™์ž‘ํ•˜๋„๋ก ํ–ˆ๋‹ค.

 

 

8๏ธโƒฃ ๊ธ€ ์ž‘์„ฑ 

๊ธ€ ์ž‘์„ฑ ํŽ˜์ด์ง€ 
BoardController.java 

list, view ํ™”๋ฉด์—์„œ ์‹ ๊ทœ ๋“ฑ๋ก ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ๋‚˜ํƒ€๋‚˜๋Š” ํ™”๋ฉด์œผ๋กœ ์ƒˆ๋กœ์šด ๊ธ€์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋Š” ํŽ˜์ด์ง€์ด๋‹ค.

 

write.jsp

๊ธ€ ์ž‘์„ฑ ํŽ˜์ด์ง€์—์„œ ๋“ฑ๋ก ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด writeOk.do๊ฐ€ ์‹คํ–‰๋˜์–ด ์ž‘์„ฑํ•œ ๊ธ€์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ฐ˜์˜๋œ๋‹ค. 

BoardController.java

๊ธ€์„ ๋“ฑ๋กํ•œ ํ›„์—๋Š” ๋‹ค์‹œ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธํ•˜์—ฌ list.do๋กœ ์ด๋™ํ•œ๋‹ค. 

 

9๏ธโƒฃ ๊ธ€ ์ˆ˜์ • 

ํŠน์ • ๊ธ€ ์กฐํšŒ ํŽ˜์ด์ง€ 

๊ธ€์„ ์ˆ˜์ •ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ˆ˜์ •ํ•˜๊ธฐ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด 

๊ธ€ ์ˆ˜์ • ํŽ˜์ด์ง€ 

์ด๋ ‡๊ฒŒ ์ œ๋ชฉ๊ณผ ๋‚ด์šฉ์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ๋Š” ํŽ˜์ด์ง€๋กœ ๋ฐ”๋€๋‹ค. 

wr_uid์™€ name ๋“ฑ์€ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋„๋ก ํ–ˆ๋‹ค. 

BoardController.java

์šฐ์„  ๊ธ€ ์ˆ˜์ • ํŽ˜์ด์ง€์—์„œ๋Š” ์›๋ž˜ ์ˆ˜์ • ์ „ ๊ธ€์ด ํ‘œ์‹œ๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— selectOne ์„ ํ†ตํ•ด ํŠน์ • ๊ธ€์„ ์กฐํšŒํ•ด ํ‘œ์‹œํ•ด์ค€๋‹ค. 

update.jsp
BoardController.java

๊ธ€์„ ์ˆ˜์ •ํ•œ ํ›„์— ์ˆ˜์ •๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด updateOk.do๊ฐ€ ์‹คํ–‰๋˜๋ฉด์„œ ๊ธ€ ์ˆ˜์ •์„ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ๋ฐ˜์˜ํ•˜๊ณ  ๋‚œ ํ›„์— 

redirect๋กœ list๋กœ ํ•œ๋‹ค. 

 

๐Ÿ”Ÿ ๊ธ€ ์‚ญ์ œ 

๊ธ€ ์‚ญ์ œ ํ™•์ธ ํŽ˜์ด์ง€ 
BoardController

BoardController์—์„œ๋Š”  @PathVariable ์–ด๋…ธํ…Œ์ด์…˜์„ ํ†ตํ•ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ urlํ˜•์‹์œผ๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค. 

๊ธ€ ์‚ญ์ œ๋Š” ํŽ˜์ด์ง€๊ฐ€ ๋”ฐ๋กœ ํ•„์š” ์—†๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น ๊ธ€์˜ uid๋ฅผ urlํ˜•์‹์œผ๋กœ ๋ฐ›๋„๋ก ํ–ˆ๋‹ค. 

์‚ฌ์šฉ์ž๊ฐ€ ํ™•์ธ ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์‚ญ์ œ๊ฐ€ ๋˜๊ณ , ๋‹ค์‹œ ๋ชฉ๋ก์œผ๋กœ ๋Œ์•„๊ฐ€๋„๋ก ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ•œ๋‹ค. 

 

 

 

 

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๊ฐ„๋‹จํ•œ ๊ฒŒ์‹œํŒ์„ ์กฐํšŒ, ์ˆ˜์ •, ์‚ญ์ œ, ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ๋‹ค. 

์ด์ œ ์—ฌ๊ธฐ์„œ ์ œ๋ชฉ์ด๋‚˜ ์ž‘์„ฑ์ž๋Š” ๋ฐ˜๋“œ์‹œ ์ž‘์„ฑํ•˜๋„๋ก ์œ ํšจ์„ฑ์„ ์ ๊ฒ€ํ•œ๋‹ค๋˜๊ฐ€, 

์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค๋ฉด ์—๋Ÿฌ ํŽ˜์ด์ง€๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ฑฐ๋‚˜ ํ•˜๋Š” ๋“ฑ ํ•ด์„œ 

์ ์  ์ถ”๊ฐ€ํ•ด ๋‚˜๊ฐˆ ์˜ˆ์ •์ด๋‹ค!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90