Spring MVC, Mybatis [2] ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ์ž ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ

2021. 11. 24. 14:14ใ†Spring

728x90

๊ทธ๋™์•ˆ Spring ๊ณต๋ถ€๋ฅผ ํ•˜๋ฉด์„œ ํ•ด์™”๋˜ ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ๋ฅผ 

์ด์ œ ๊ฐ„๋‹จํ•˜์ง€๋งŒ ํ™”๋ฉด ๊ตฌํ˜„๊นŒ์ง€ ํ•ด์„œ ๋งŒ๋“ค์–ด ๋ณผ ์˜ˆ์ •์ด๋‹ค.

 

Spring MVC Model2 ๋ฅผ ํ™œ์šฉํ•ด์„œ ํ•  ์˜ˆ์ •์ด๋‹ค. 

 

 

1. Users ํ…Œ์ด๋ธ” 

Users ํ…Œ์ด๋ธ”์€ userid, name, gender, city๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. 

 

2. ์„œ๋น„์Šค ๊ณ„์ธต 

UserService ์ธํ„ฐํŽ˜์ด์Šค์™€ ์ด๋ฅผ ๊ตฌํ˜„ํ•œ UserServiceImple๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. 

 

1๏ธโƒฃ UserService

 

2๏ธโƒฃ UserServicImple

 

3. ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๊ณ„์ธต 

UserDAO ์ธํ„ฐํŽ˜์ด์Šค์™€ ์ด๋ฅผ ๊ตฌํ˜„ํ•œ UserDAOJDBC

 

1๏ธโƒฃ UserDAO

 

2๏ธโƒฃ UserDAOJDBC

 

4. Mapping ํŒŒ์ผ 

 

 

5. MyBatis-Config ํŒŒ์ผ 

VO ๊ฐ์ฒด ์„ค์ • 

 

 

6. Mapper ์ธํ„ฐํŽ˜์ด์Šค 

 

 

7. ๋นˆ ์„ค์ • ํŒŒ์ผ 

 

1๏ธโƒฃ DataSource ์„ค์ • 

์ด๋•Œ property ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด์„œ ๋ฐ์ดํ„ฐ ๊ฐ’์„ ์ž…๋ ฅํ•ด์ค„ ๋•Œ๋Š” <context:property-placeholder> ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด ํ•ด๋‹น ํŒŒ์ผ์˜ ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด์ค˜์•ผํ•œ๋‹ค. 

 

2๏ธโƒฃ MyBatis ์„ค์ • 

SqlSessionFactoryBean ์„ ๋นˆ ์„ค์ •ํŒŒ์ผ์— ๋“ฑ๋กํ•ด์ค„ ๋•Œ dataSource์™€ myBatis ์„ค์ •ํŒŒ์ผ ๊ฒฝ๋กœ, ๊ทธ๋ฆฌ๊ณ  MappingํŒŒ์ผ์˜ ๊ฒฝ๋กœ๊นŒ์ง€ ์ง€์ •ํ•ด์ค˜์•ผํ•œ๋‹ค. 

SqlSessionTemplate๋„ ๋นˆ์„ค์ •ํŒŒ์ด๋ ˆ ๋“ฑ๋กํ•ด์ค€๋‹ค. 

 

 

8. Spring MVC ๊ธฐ๋ฐ˜ ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ 

 

1๏ธโƒฃ ํด๋ผ์ด์–ธํŠธ์˜ ๋ชจ๋“  ์š”์ฒญ์„ ๋ฐ›๋Š” DispatcherServlet์„ web.xml์— ์„ค์ •ํ•œ๋‹ค. 

์‚ฌ์‹ค Spring mvc project๋กœ ๋งŒ๋“  ํ”„๋กœ์ ํŠธ๋ผ๋ฉด ์ด๊ฑด ๋ชจ๋‘ ์ž‘์„ฑ๋˜์–ด ์žˆ์„๊ฑฐ๋ผ ๋”ฐ๋กœ ์ถ”๊ฐ€ํ•˜์ง€๋Š” ์•Š์•„๋„ ๋œ๋‹ค.

 

โญ๋Œ€์‹  ํ•œ๊ธ€ ์ธ์ฝ”๋”ฉ์„ ์œ„ํ•ด์„œ ์ด ์ฝ”๋“œ๋Š” ๋ฐ‘์— ์ถ”๊ฐ€ํ•ด์ฃผ๊ธฐ!

<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>

 

 

2๏ธโƒฃ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  Controller๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.

 

3๏ธโƒฃ Spring Bean์œผ๋กœ Controller ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค. 

@Controller๋กœ ์ง€์ •ํ•ด์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์— 

ํŒจํ‚ค์ง€๋ช…๋งŒ ์ž˜ ์ž‘์„ฑํ•ด์ค€๋‹ค. 

 

4๏ธโƒฃ JSP์„ ์ด์šฉํ•œ View ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. 

 

5๏ธโƒฃ ๋ธŒ๋ผ์šฐ์ €์ƒ์—์„œ jsp๋ฅผ ์‹คํ–‰ํ•ด๋ณธ๋‹ค. 

 

 

 

9. Spring MVC ๊ธฐ๋ฐ˜์˜ ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ 

 

1๏ธโƒฃ ์‚ฌ์šฉ์ž ๋ชฉ๋ก ์กฐํšŒ 

- ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  POJO ํ˜•ํƒœ์˜ UserController ํด๋ž˜์Šค ์ž‘์„ฑ

- Controller ํด๋ž˜์Šค์— @Controller ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธ

- ์‚ฌ์šฉ์ž ๋ชฉ๋ก์„ ์กฐํšŒํ•˜๋Š” getUserList() ๋ฉ”์„œ๋“œ๋ฅผ ์„ ์–ธํ•˜๊ณ , @RequestMapping ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•œ๋‹ค. 

UserController

- userList.jsp ํŽ˜์ด์ง€์— View ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp ์‹คํ–‰ํ•œ๋‹ค. 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>UserList</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

	<div class="container">
		<h2 class="text-center">์‚ฌ์šฉ์ž ๋ชฉ๋ก </h2>
		<table class="table table-bordered table table-hover">
			<thead>
				<tr>
					<th>์•„์ด๋”” </th>
					<th>์ด๋ฆ„</th>
					<th>์„ฑ๋ณ„</th>
					<th>๊ฑฐ์ฃผ์ง€</th>
					<th>&nbsp;</th>
					<th>&nbsp;</th>
				</tr>
			</thead>
			
			<tbody>
				<c:forEach var="user" items="${userlist }">
					<tr>
						<td>
							<a href = "getUser.do?id=${user.userid}"> ${user.userid} </a>
						</td>
						
						<td>${user.name}</td>
						<td>${user.gender} </td>
						<td>${user.city}</td>
						<td>
							<a href="updateUserForm.do?id=${user.userid }">์ˆ˜์ •</a>
						</td>
						<td>
							<a href="deleteUser.do/${user.userid }">์‚ญ์ œ</a>
						</td>
						
					</tr>
				</c:forEach>
				<tr>
					<td colspan="7">
						<a href="insertUserForm.do">์‚ฌ์šฉ์ž ๋“ฑ๋ก</a>
					</td>
				</tr>
			</tbody>
		</table>
	</div>

</body>
</html>

๊ฒฐ๊ณผํ™”๋ฉด 

 

 

โ— ViewResolver 

 ViewResolver๋Š” Controller์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ ์–ด๋–ค view์— ๋ณด์—ฌ์ค„ ๊ฒƒ์ธ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•œ๋‹ค.

InternalResourceViewResolver๋Š” jsp๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ view๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. 

prefix๋Š” Controller๊ฐ€ ๋ฆฌํ„ดํ•œ view ์ด๋ฆ„ ์•ž์— ๋ถ™์„ ์ ‘๋‘์–ด์ด๋‹ค. 

suffix๋Š” Controller๊ฐ€ ๋ฆฌํ„ดํ•œ view์ด๋ฆ„ ๋’ค์— ๋ถ™์„ ํ™•์žฅ์ž์ด๋‹ค. jsp ๋ผ๊ณ  ํ•ด์ฃผ๋ฉด ์ด์ œ returnํ•  ๋•Œ ๋งˆ๋‹ค .jsp๋ฅผ ๋ถ™์ด์ง€ ์•Š์•„๋„ ๋œ๋‹ค. 

 

 

2๏ธโƒฃ ํŠน์ • ์‚ฌ์šฉ์ž ์กฐํšŒ 

- ์‚ฌ์šฉ์ž ๋ชฉ๋ก์„ ์กฐํšŒํ•˜๋Š” getUser(String id) ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  @RequestMapping ๊ณผ @RequestParam ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•œ๋‹ค. 

โ— @RequestParam ์€ http ์š”์ฒญ์— ํฌํ•จ๋œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ฐธ์กฐ์‹œ ์‚ฌ์šฉํ•œ๋‹ค. 

 

- userList.jsp ํŽ˜์ด์ง€๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค.

 ํ•ด๋‹น userid๋ฅผ ํด๋ฆญํ•˜๋ฉด ํŠน์ • ์‚ฌ์šฉ์ž๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋Š” UserInfo ํ™”๋ฉด์œผ๋กœ ๋„˜์–ด๊ฐ„๋‹ค. 

 

- userInfo.jsp ํŽ˜์ด์ง€์— view ์˜์—ญ์˜ ์ฝ”๋“œ ์ž‘์„ฑ 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${user.userid }์‚ฌ์šฉ์ž ์ƒ์„ธ ์ •๋ณด</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="container">
		<h2 class="text-center">์‚ฌ์šฉ์ž ์ƒ์„ธ ์ •๋ณด</h2>
		<table class ="table table-bordered table table-hover">
			<tr><td>์•„์ด๋”” : </td><td>${user.userid }</td></tr>
			<tr><td>์ด๋ฆ„ :</td><td>${user.name }</td></tr>
			<tr><td>์„ฑ๋ณ„ :</td><td>${user.gender }</td></tr>
			<tr><td>๊ฑฐ์ฃผ์ง€ : </td><td>${user.city }</td></tr>
			
		</table>
	</div>

</body>
</html>

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp๋ฅผ ์‹คํ–‰ 

 

 

โ— ModleAndView ํด๋ž˜์Šค 

Controller์—์„œ Service์—์„œ ํ˜ธ์ถœํ•œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ›์•„์„œ View์— ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด ์ „๋‹ฌ๋ฐ›์€ ๋ฐ์ดํ„ฐ์™€ ํ™”๋ฉด ์ •๋ณด๋ฅผ ModelAndView ๊ฐ์ฒด์— ์ €์žฅํ•œ๋‹ค. 

 

 

 

3๏ธโƒฃ ์‚ฌ์šฉ์ž ์ •๋ณด ๋“ฑ๋ก ํ™”๋ฉด 

- ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๋“ฑ๋กํ•˜๋Š” ํ™”๋ฉด์„ ํฌ์›Œ๋”ฉ ํ•ด์ฃผ๋Š” insertUserForm() ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  @RequestMapping ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธ

-> ArrayList์— ๊ฐ๊ฐ ์„ฑ๋ณ„๊ณผ ๋„์‹œ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋„ฃ์–ด์ฃผ๊ณ , ์ด๋ฅผ userInsert ํ™”๋ฉด์— ์ „๋‹ฌํ•ด์ฃผ๋ฉด ์ด๋ฅผ ํ™”๋ฉด์—์„œ ์ถœ๋ ฅํ•ด์ค€๋‹ค.

- userList.jsp ํŽ˜์ด์ง€๋ฅผ ์ˆ˜์ •

- userInsert.jsp ํŽ˜์ด์ง€์—์„œ View ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>        
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์‚ฌ์šฉ์ž ์ •๋ณด ๋“ฑ๋ก</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="container">
		<h2 class="text-center">์‚ฌ์šฉ์ž ์ •๋ณด ๋“ฑ๋ก</h2>
		<div>
			<form method="post" action="insertUser.do">
		
			<table class="table table-bordered table table-hover">
				<tr>
					<td>์•„์ด๋””</td>
					<td><input type="text" name="userid"/></td>
				</tr>
				
				<tr>
					<td>์ด๋ฆ„</td>
					<td><input type="text" name="name"/></td>
				</tr>
				
				<tr>
					<td>์„ฑ๋ณ„</td>
					<td>
						<c:forEach var="genderName" items="${map.genderList }">
							<input type="radio" name="gender" value="${genderName }">${genderName }
						</c:forEach>
					</td>
				</tr>
				
				<tr>
					<td>๊ฑฐ์ฃผ์ง€</td>
					<td>
						<select name="city">
							<c:forEach var="cityName" items="${map.cityList }">
								<option value="${cityName }">${cityName }</option>
							</c:forEach>
						
						</select>
					</td>
				
				</tr>
				
				<tr>
					<td colspan="2" class="text-center">
						<input type="submit" value="๋“ฑ๋ก"/>
					</td>
				</tr>
				
				<tr>
					<td colspan="2" class="text-center">
						<a href="getUserList.do">์‚ฌ์šฉ์ž ๋ชฉ๋ก ๋ณด๊ธฐ</a>
					</td>
				</tr>
			</table>
			</form>
		</div>
	</div>
</body>
</html>

map์— ๋‹ด๊ฒจ ์ „๋‹ฌ๋œ genderList์™€ cityList๋ฅผ ๋ฐ›์•„ ํ™”๋ฉด์— ์ถœ๋ ฅํ•ด์คŒ.

 

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp๋ฅผ ์‹คํ–‰ 

 

 

4๏ธโƒฃ ์‚ฌ์šฉ์ž ์ •๋ณด ๋“ฑ๋ก

- ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ๋“ฑ๋กํ•˜๋Š” insertUser(@ModelAttribute UserVO user) ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  @RequestMapping๊ณผ @ModelAttribute ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•œ๋‹ค. 

๋“ฑ๋กํ›„์—” ๋ชฉ๋ก ์กฐํšŒ๊ฐ€ redirect ๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋“ฑ๋ก๋œ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์•ผํ•œ๋‹ค. 

โ— @ModelAttribute 

http ์š”์ฒญ์— ํฌํ•จ๋œ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ชจ๋ธ ๊ฐ์ฒด๋กœ ๋ฐ”์ธ๋”ฉํ•ด์ค€๋‹ค. 

 

- userInsert.jsp ํŽ˜์ด์ง€์— View ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ 

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp ์‹คํ–‰ 

 

5๏ธโƒฃ ์‚ฌ์šฉ์ž ์ˆ˜์ • ํ™”๋ฉด 

- ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ํ™”๋ฉด์„ ํฌ์›Œ๋”ฉ ํ•ด์ฃผ๋Š” updateUserForm(@RequestParam String id) ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  

@RequestMapping ๊ณผ @RequestParma ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธ

-> ์‚ฌ์šฉ์ž ํ™”๋ฉด์„ ์ˆ˜์ •ํ•  ๋•Œ๋Š” ์šฐ์„  ์ˆ˜์ • ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด ์‚ฌ์šฉ์ž์˜ ์ •๋ณด๊ฐ€ ์ž…๋ ฅ๋˜์–ด ์žˆ์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— UserVO ๊ฐ์ฒด๋„ ๋‹ด๊ณ , ์•„๊นŒ ์‚ฌ์šฉ์ž ๋“ฑ๋กํ™”๋ฉด์—์„œ ์ž‘์„ฑํ–ˆ๋˜ genderList์™€ cityList๋„ ํฌํ•จํ•ด์„œ Map์— ์ €์žฅํ•˜์—ฌ userUpdate.jsp์— ๋ณด๋‚ธ๋‹ค. 

 

-userList.jsp ํŽ˜์ด์ง€ ์ˆ˜์ • 

 

- userUpdate.jsp ํŽ˜์ด์ง€์—์„œ View ์˜์—ญ์˜ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>     
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์‚ฌ์šฉ์ž ์ •๋ณด ์ˆ˜์ •</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
	<div class="container">
		<h2 class="text-center">์‚ฌ์šฉ์ž ์ •๋ณด ์ˆ˜์ •</h2>
		<div>
		<form method="post" action="updateUser.do">		
			<input type="hidden" name="userid" value="${map.user.userid }"/>
			<table class="table table-bordered table table-hover">
				<tr>
					<td>์•„์ด๋””</td>
					<td>${map.user.userid }</td>
				</tr>
				
				<tr>
					<td>์ด๋ฆ„</td>
					<td><input type="text" name="name" value="${map.user.name }"/> </td>
				</tr>
				
				<tr>
					<td>์„ฑ๋ณ„</td>
					<td>
						<c:forEach var="genderName" items="${map.genderList }">
							<c:choose>
								<c:when test="${genderName eq map.user.gender }">
									<input type="radio" name="gender" value="${genderName }" checked="checked"> ${genderName }
								</c:when>
								
								<c:otherwise>
									<input type="radio" name="gender" value="${genderName }"> ${genderName }
								
								</c:otherwise>
							
							</c:choose>
						
						</c:forEach>
						
					</td>
				</tr>
				
				<tr>
					<td>๊ฑฐ์ฃผ์ง€</td>
					<td>
						<select name="city">
							<c:forEach var="cityName" items="${map.cityList }">
								<c:choose>
									<c:when test="${cityName eq map.user.city }">
										<option value="${cityName }" selected> ${cityName } </option>
									</c:when>
									
									<c:otherwise>
										<option value="${cityName }">${cityName }</option>
									
									</c:otherwise>							
								
								</c:choose>
							
							
							</c:forEach>
						
						
						</select>
					</td>
				</tr>
				
				<tr>
					<td colspan="2" class="text-center">
						<input type="submit" value="์ˆ˜์ •">
					</td>
				</tr>
			</table>	
			</form>
		</div>	
	</div>

</body>
</html>

-> hidden์„ ํ•˜๋Š” ์ด์œ ๋Š” ์ˆ˜์ •ํ•˜๊ณ  submit ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅผ ๋•Œ userid๊ฐ’๋„ ์ „๋‹ฌ์€ ๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— !!!

userid๋Š” ์ˆ˜์ • ๋ถˆ๊ฐ€๋ผ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋„๋ก ๊ณ ์ •ํ•ด์„œ ํ™”๋ฉด์— ๋ณด์—ฌ์ง„๋‹ค. 

 

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp ๋ฅผ ์‹คํ–‰ 

 

 

 

6๏ธโƒฃ ์‚ฌ์šฉ์ž ์ˆ˜์ •

- ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜๋Š” ํ™”๋ฉด์„ ํฌ์›Œ๋”ฉ ํ•ด์ฃผ๋Š” updateUser(@ModelAttribute UserVo user) ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ , 

@RequestMapping ๊ณผ @ModelAttribute ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธํ•œ๋‹ค. 

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

- userUpdate.jsp ํŽ˜์ด์ง€์— view ์˜์—ญ ์ฝ”๋“œ ์ž‘์„ฑ 

 

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp ๋ฅผ ์‹คํ–‰

 

 

7๏ธโƒฃ ์‚ฌ์šฉ์ž ์ •๋ณด ์‚ญ์ œ 

- ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ ์‚ญ์ œํ•˜๋Š” deleteUser(@pathVariable String id) ๋ฉ”์„œ๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ณ  @RequestMapping ๊ณผ @PathVariable ์–ด๋…ธํ…Œ์ด์…˜์„ ์„ ์–ธ 

โ— @PathVariable

ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ url ํ˜•์‹์œผ๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค€๋‹ค.

 

- userList.jsp ํŽ˜์ด์ง€๋ฅผ ์ˆ˜์ • 

- ๋ธŒ๋ผ์šฐ์ € ์ƒ์—์„œ jsp ๋ฅผ ์‹คํ–‰ 

user11 ์‚ญ์ œ๋จ.

 

 

 

 

 

 

 

728x90