๐œ‡ Spring Boot ์˜ˆ์ œ4 (ํšŒ์›๊ด€๋ฆฌ)

@Autowiredยท2022๋…„ 1์›” 10์ผ
0

Spring Boot

๋ชฉ๋ก ๋ณด๊ธฐ
5/11

ํšŒ์›๊ด€๋ฆฌ ์ˆ˜์ • & ์‚ญ์ œ Rest API ๋ฐฉ์‹์œผ๋กœ ๋งŒ๋“ค๊ธฐ!

  • ์‚ฌ์šฉ IDE : IntelliJ IDEA Ultimate
  • ์‚ฌ์šฉ DB : MySQL
  • ์‚ฌ์šฉ ์–ธ์–ด & SDK : Java & Amazon correto 11
  • thymeleaf ์‚ฌ์šฉ์„ ๊ฐ€๊ธ‰์  ์ค„์ธ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.
  • ajax๋กœ ์กฐํšŒ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์™€ ๋™์ผํ•˜๋ฏ€๋กœ ๋นผ๊ฒ ์Šต๋‹ˆ๋‹ค.
  • ์ •๋ฆฌ๋ณธ์ž…๋‹ˆ๋‹ค ์ฐธ๊ณ ์šฉ์œผ๋กœ๋งŒ ๋ด์ฃผ์„ธ์š”!

์ด์ „ ๊ธ€
ฮธ Spring Boot ์˜ˆ์ œ1 (ํšŒ์›๊ด€๋ฆฌ)
๐œ… Spring Boot ์˜ˆ์ œ2 (ํšŒ์›๊ด€๋ฆฌ)
๐œ† Spring Boot ์˜ˆ์ œ3 (ํšŒ์›๊ด€๋ฆฌ)


์‚ญ์ œ

  • ์ˆœ์„œ

    1. findAll.html์—์„œ Controller๋กœ memberId(pk๋กœ ์“ฐ๋Š” ํšŒ์›๋ฒˆํ˜ธ) ์ „๋‹ฌ

    2. Controller์—์„œ Service๋กœ ์ „๋‹ฌ

    3. Service์—์„œ jpa ํ˜ธ์ถœ ๋ฐ ์‚ญ์ œ ์ง„ํ–‰

    4. ์‚ฌ์šฉ์ž๊ฐ€ ์ง€์ •ํ•œ ์ž‘์—… ์ˆ˜ํ–‰


findAll.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<script>
function deleteById(memberId) {
	console.log(memberId)
	const reqUrl = "/member/"+memberId
	$.ajax({
		type: "delete",
		url: reqUrl,
		// dataType: "json", ๋ฐ›์•„์˜ฌ ํ•„์š”๊ฐ€ ์—†์œผ๋ฉด ์ƒ๋žต๊ฐ€๋Šฅ
		success: function () {
			console.log("ajax ์„ฑ๊ณต")
			// ์‚ญ์ œ ์„ฑ๊ณต ์‹œ ํšŒ์›๋ชฉ๋ก ํŽ˜์ด์ง€๋ฅผ ๋‹ค์‹œ ์š”์ฒญ
			location.href = "/member/"
		},
		error: function () {
			alert("ajax ์‹คํŒจ")
		}

	})
}

	// ์•„๋ž˜๋„ ํ•จ์ˆ˜์„ ์–ธ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜์ž„.
	// ํ•จ์ˆ˜์ด๋ฆ„ : deleteFn, ๋งค๊ฐœ๋ณ€์ˆ˜ : memberId
	const deleteFn = (memberId) => {
		console.log(memberId)
	}

	// ํ•จ์ˆ˜์ด๋ฆ„ : deleteFn2, ๋งค๊ฐœ๋ณ€์ˆ˜ : X
	const deleteFn2 = () => {
	
	}
</script>
<body>
	<h2>findAll.html</h2>
	<table>
		<thead>
			<tr>
				<th>๋ฒˆํ˜ธ</th>
				<th>์ด๋ฉ”์ผ</th>
				<th>๋น„๋ฐ€๋ฒˆํ˜ธ</th>
				<th>์ด๋ฆ„</th>
				<th>์กฐํšŒ</th>
				<th>์‚ญ์ œ(get)</th>
				<!-- ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ์•„๋ž˜ delete ๋ฐฉ์‹์œผ๋กœ ๋ณด๋‚ด๋Š”๊ฑธ ์‚ฌ์šฉํ•˜๋Š”๊ฒ๋‹ˆ๋‹ค. -->
				<th>์‚ญ์ œ(delete)</th>
			</tr>
		</thead>
		<tbody>
			<tr th:each="member: ${memberList}">
				<td th:text="${member.memberId}">๋ฒˆํ˜ธ</td>
				<td th:text="${member.memberEmail}">์ด๋ฉ”์ผ</td>
				<td th:text="${member.memberPassword}">๋น„๋ฐ€๋ฒˆํ˜ธ</td>
				<td th:text="${member.memberName}">์ด๋ฆ„</td>
				<!-- detail ์ฃผ์†Œ ์ฒ˜๋ฆฌ๋ฐฉ์‹ @{|/์ฃผ์†Œ/${๊ฐ™์ด ๋ณด๋‚ผ ๋ฐ์ดํ„ฐ}|} -->
				<td><a th:href="@{|/member/${member.memberId}|}">์กฐํšŒ</a></td>
				<td><a th:href="@{|/member/delete/${member.memberId}|}">์‚ญ์ œ</a></td>
				<!-- ์‚ญ์ œ ๋ฒ„ํŠผ ํด๋ฆญ ์‹œ delete ํ•จ์ˆ˜ ํ˜ธ์ถœ -->
				<!-- ํ•จ์ˆ˜ํ˜ธ์ถœํ•˜๋ฉด์„œ memeberId ๋„˜๊ฒจ์•ผํ•จ -->
				<!-- delelte ํ•จ์ˆ˜() : /member/memberId ์ฃผ์†Œ๋กœ ์š”์ฒญํ•˜๋ฉฐ, ์š”์ฒญ ๋ฉ”์„œ๋“œ๋Š” delete -->
				<td><button th:onclick="deleteById([[${member.memberId}]])">์‚ญ์ œ</button></td>
			</tr>
		</tbody>
	</table>
</body>
</html>

ajax๋กœ ๊ฐ’์„ ๋ณด๋ƒˆ์œผ๋‹ˆ ์ด์ œ Controller์—์„œ ๋ฐ›์„ ์ค€๋น„๋ฅผ ํ•ด๋ด…์‹œ๋‹ค.


Controller

// ํšŒ์›์‚ญ์ œ(/member/5)
@DeleteMapping("{memberId}")
public ResponseEntity deleteById2(@PathVariable Long memberId) {
	ms.deleteById(memberId);
	/*
	    ๋‹จ์ˆœ ํ™”๋ฉด์ถœ๋ ฅ์ด ์•„๋‹Œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฆฌํ„ดํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฆฌํ„ด๋ฐฉ์‹
	    ResponseEntity : ๋ฐ์ดํ„ฐ & ์ƒํƒœ์ฝ”๋“œ(200, 400, 404, 405, 500 ๋“ฑ ์˜ค๋ฅ˜์ฝ”๋“œ)๋ฅผ ํ•จ๊ป˜ ๋ฆฌํ„ดํ•  ์ˆ˜ ์žˆ์Œ.
	    @ResponseBody : ๋ฐ์ดํ„ฐ๋ฅผ ๋ฆฌํ„ดํ•  ์ˆ˜ ์žˆ์Œ.
	*/
	// 200์ฝ”๋“œ๋ฅผ ๋ฆฌํ„ด (200์€ OK๋ผ๋Š” ๋œป์œผ๋กœ ์ •์ƒ์ ์œผ๋กœ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์—ˆ๋‹ค ๋ผ๋Š” ๋œป)
	// ์ƒํƒœ์ฝ”๋“œ๊ฐ€ OK(200)๋ฉด ๋ฐ”๋กœ ajax์—์„œ success๊ฐ€ ํ˜ธ์ถœ
	return  new ResponseEntity(HttpStatus.OK);
}

Service

  • Service๋Š” ์–ด์ œ ๋งŒ๋“  ๋ฉ”์„œ๋“œ๋ฅผ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์ƒ๋žตํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :D

์•ž์—์„œ๋ถ€ํ„ฐ ์ญ‰ ์ž˜ ๋”ฐ๋ผ์˜ค์…จ๋‹ค๋ฉด ๋ฌธ์ œ๋Š” ์ „ํ˜€ ์—†์„๊ฒ๋‹ˆ๋‹ค.
์ƒˆ๋กœ์šด๊ฑธ ๊ณ„์† ๋ฐฐ์šฐ๊ธฐ ๋•Œ๋ฌธ์— ์–ด๋ ค์šด๊ฒŒ ์žˆ์„ ์ˆ˜ ์žˆ์œผ๋‚˜ ๊ธˆ๋ฐฉ ์ ์‘ํ•˜๋ฉด์„œ ์ž˜ํ•˜์‹ค ์ˆ˜ ์žˆ์„๊ฒ๋‹ˆ๋‹ค!!
๊ทธ๋Ÿผ ์ด์ œ ์—…๋ฐ์ดํŠธ(์ˆ˜์ •)์œผ๋กœ ๋„˜์–ด๊ฐ€๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!


์ˆ˜์ •

์ด๋ฒˆ์—๋Š” ์ˆ˜์ •์ž…๋‹ˆ๋‹ค :D
์ผ๋ฐ˜์ ์ธ ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•๊ณผ, Rest API๋ฐฉ์‹์œผ๋กœ ์ˆ˜์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ•ด๋ณผ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
๋กœ๊ทธ์ธ ํ›„ findAll๋กœ ๊ฐ€๋Š”๊ฑฐ์—์„œ mypage๋กœ ๊ฐ€๊ฒŒ๋” ๋ณ€๊ฒฝ ํ›„ ์ˆ˜์ •์€ update.html์—์„œ ์ง„ํ–‰ํ•˜๊ฒŒ ํ–ˆ์Šต๋‹ˆ๋‹ค.
Service์—์„œ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์€ ๊ฐ™์œผ๋‚˜ ์ฃผ์†Œ ์ฒ˜๋ฆฌ๋ฐฉ์‹๋งŒ ๋‹ค๋ฅด๋ฏ€๋กœ ๊ฐ™์ด ์„ค๋ช…ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!
Controller์™€ html์„ ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋†“๊ณ  ์„ค๋ช…ํ•˜๋Š”๊ฑธ๋กœ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :D


Controller

// ๋กœ๊ทธ์ธ
@PostMapping("login")
public String login(@ModelAttribute MemberLoginDTO memberLoginDTO, HttpSession session) {
	if (ms.login(memberLoginDTO)) {
		session.setAttribute(LOGIN_EMAIL,memberLoginDTO.getMemberEmail());
		// return์„ mypage๋กœ ๊ฐ€๊ฒŒ๋” ๋ณ€๊ฒฝ. ๊ทธ ์™ธ ๋‚˜๋จธ์ง€๋Š” ๋ณ€๊ฒฝํ•œ๊ฑฐ ์—†์Œ
		return "member/mypage";
	} else {
		return "member/login";
	}
}

// ์ˆ˜์ •ํ™”๋ฉด ์š”์ฒญ
@GetMapping("update")
public String updateForm(Model model, HttpSession session) {
	// jsp, html์ด ์•„๋‹Œ ๊ณณ์—์„œ๋„ session์— ๋‹ด๊ธด ๊ฐ’์„ ๊บผ๋‚ด์˜ฌ ์ˆ˜ ์žˆ์Œ.
	// ์ƒ์ˆ˜๋กœ ์„ ์–ธํ•œ ๋ณ€์ˆ˜๋กœ session์„ ์„ค์ •ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ ์‚ฌ์šฉ.
	String memberEmail = (String) session.getAttribute(LOGIN_EMAIL);
	// Object ํƒ€์ž…์œผ๋กœ ๋„˜์–ด์˜ค๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ•์ œ ํ˜• ๋ณ€ํ™˜์„ ํ•ด์ค˜์•ผํ•จ.
	// thymeleaf๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด Update์šฉ DTO๋ฅผ ํ•˜๋‚˜ ๋” ๋งŒ๋“ค์–ด์•ผํ•จ.
	// ํ•˜์ง€๋งŒ, ๊ฐ€๊ธ‰์  ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ธฐ๋กœ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ๋ƒฅ Detail์šฉ DTO ์‚ฌ์šฉ
	MemberDetailDTO memberDetailDTO = ms.findByEmail(memberEmail);
	model.addAttribute("member", memberDetailDTO);
	return "member/update";
}

// ์ผ๋ฐ˜ ์ˆ˜์ •
@PostMapping("update")
public String update(@ModelAttribute MemberDetailDTO memberDetailDTO) {
	Long memberId = ms.update(memberDetailDTO);
	// ์ˆ˜์ • ์™„๋ฃŒ ํ›„ ํ•ด๋‹นํšŒ์›์˜ ์ƒ์„ธ ํŽ˜์ด์ง€ ์ถœ๋ ฅ
	return "redirect:/member/"+memberDetailDTO.getMemberId();
}

// ์ˆ˜์ •์ฒ˜๋ฆฌ (put)
@PutMapping("{memberId}")
// json์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ „๋‹ฌ๋˜๋ฉด @RequestBody๋กœ ๋ฐ›์•„์ค˜์•ผํ•จ
public ResponseEntity update2(@RequestBody MemberDetailDTO memberDetailDTO) {
	Long memberId = ms.update(memberDetailDTO);
	return new ResponseEntity(HttpStatus.OK);
}

mypage.html & update.html ์ƒ์„ฑ

  • mypage.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
	<h2>mypage.html</h2>
	<!-- common ์•ˆ ๋‹ด๊ฒจ์žˆ๋Š” ๊ฐ’์„ ์“ฐ๋Š”๊ฒƒ, ์ƒ์ˆ˜๋กœ ์„ ์–ธํ•œ ๋ณ€์ˆ˜ ์ด๋ฆ„์„ ์“ฐ๋Š”๊ฒƒ์ด ์•„๋‹˜! -->
	์„ธ์…˜ : <p th:text="${session['loginEmail']}"></p>
	<!-- ์ •๋ณด์ˆ˜์ • ๋งํฌ๋ฅผ ํด๋ž™ํ•˜๋ฉด update.html์— DB์— ์ €์žฅ๋œ ์ •๋ณด๋ฅผ form, inputํƒœ๊ทธ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ถœ๋ ฅ, ์ด๋ฆ„๋งŒ ์ˆ˜์ • ๊ฐ€๋Šฅํ•˜๋„๋ก -->
	<a href="/member/update/">์ •๋ณด์ˆ˜์ •</a>

</body>
</html>

  • update.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script>
// ํ•จ์ˆ˜ ์ด๋ฆ„์ด memberUpdate, ๋งค๊ฐœ๋ณ€์ˆ˜๊ฐ€ ์—†๋Š” ํ˜•ํƒœ -> function memberUpdate() ์™€ ๊ฐ™์€ ๋œป
const memberUpdate = () => {
	console.log('์ˆ˜์ • ํ•จ์ˆ˜ ํ˜ธ์ถœ')
	// DOM API๋ฅผ ์ด์šฉํ•˜์—ฌ memberId, ์ด๋ฉ”์ผ, ๋น„๋ฐ€๋ฒˆํ˜ธ, ์ด๋ฆ„์„ ๊ฐ€์ ธ์™€์„œ ๊ฐ๊ฐ javascript ํ•จ์ˆ˜์— ๋‹ด์œผ์‹œ์˜ค.
	const id = document.getElementById("memberID").value
	const email = document.querySelector("#memberEmail").value
	// jQuary ๋ฌธ๋ฒ•์œผ๋กœ id๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ.
	const password = $("#memberPassword").val()
	const name = $("#memberName").val()
	// ์œ„ ์ฝ”๋“œ ์ „๋ถ€ ๋˜‘๊ฐ™์€ ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ์ž„. (value๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ)
	// const name = "[[${member.memberName}]]"
	// ์œ„ ์ฝ”๋“œ๋Š” DB์—์„œ ๊ฐ€์ ธ์˜จ ๋‚ด์šฉ์„ ๋‹ค์‹œ ๋„ฃ๋Š”๊ฒƒ์ด๋ฏ€๋กœ ์—…๋ฐ์ดํŠธ์—์„œ๋Š” ์‚ฌ์šฉ ๋ถˆ๊ฐ€.

	// javascript object์— ๋‹ด์•„์„œ ajax ์ปจํŠธ๋กค๋Ÿฌ์— ๋ณด๋ƒ„.
	// stringigfy : ๋ฐ์ดํ„ฐ๋ฅผ JSONํƒ€์ž…์œผ๋กœ ๋งŒ๋“ค๊ฒ ๋‹ค๋Š” ์ฝ”๋“œ
	const updateData = JSON.stringify({
		memberId: id,
		memberEmail: email,
		memberPassword: password,
		memberName: name
	})
	console.log(updateData) // ์ฝ˜์†”์— ์ฐ์–ด๋ณด๋ฉด jsonํƒ€์ž…์œผ๋กœ ๋‹ด๊ธด๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
	const reqUrl = "/member/"+id
	$.ajax({
		// put(์ „์ฒด ๋ฎ์–ด์“ฐ๊ธฐ), patch(์ˆ˜์ •์ด ํ•„์š”ํ•œ ๊ฒƒ๋งŒ ๋ฐ”๊ฟˆ)
		type: "put",
		data: updateData,
		url: reqUrl,
		// jsonํƒ€์ž…์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ผ๋•Œ๋Š” ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๊ผญ ์จ์•ผํ•จ.
		contentType: "application/json",
		success: function () {
			location.href = "/member/"+id;
  			// ์ˆ˜์ • ์„ฑ๊ณต ์‹œ /member/{memberId} ๋กœ ๊ฐ€๊ฒ ๋‹ค.(ํšŒ์› ์ƒ์„ธ์กฐํšŒ)
		},
		error: function () {
			alert("ajax ์‹คํŒจ")
		}
	})
}
</script>
</head>
<body>
<h2>save.html</h2>
<form action="/member/update" method="post">
    <input type="hidden" name="memberId" id="memberID" th:value="${member.memberId}" placeholder="ํšŒ์›๋ฒˆํ˜ธ" readonly>
    <input type="text" name="memberEmail" id="memberEmail" th:value="${member.memberEmail}" placeholder="์ด๋ฉ”์ผ" readonly>
    <input type="text" name="memberPassword" id="memberPassword" th:value="${member.memberPassword}" placeholder="๋น„๋ฐ€๋ฒˆํ˜ธ">
    <input type="text" name="memberName" id="memberName" th:value="${member.memberName}" placeholder="์ด๋ฆ„">
    <input type="submit" value="์ˆ˜์ •">
    <input type="button" value="์ˆ˜์ •(put๋ฐฉ์‹)" th:onclick="memberUpdate()">
    <!-- ๋ˆ„๋ฅผ ์‹œ ๋ฐ”๋กœ ๊ฐ€์ง€๋Š”๊ฒŒ ์•„๋‹Œ ๋ฌด์–ธ๊ฐ€ ๋™์ž‘ ํ›„ ๊ฐ€๊ฒŒํ•˜๊ณ ์‹ถ์„ ๋•Œ ํƒ€์ž…์„ ๋ฒ„ํŠผ์œผ๋กœ ์‚ฌ์šฉ -->
</form>
</body>
</html>

Service

JPA์—์„œ ์ง€์›ํ•˜๋Š” ๊ธฐ๋Šฅ ์ค‘ ํ•˜๋‚˜์ธ๋ฐ, save ๋ฉ”์„œ๋“œ, ์ฆ‰ ํšŒ์›๊ฐ€์ž… ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉ ์‹œ
์ž๋™์œผ๋กœ DB์—์„œ ๊ธฐ์กด์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋Š”์ง€ ๋น„๊ต ํ›„ ์žˆ์„ ์‹œ ์—…๋ฐ์ดํŠธ ์ฟผ๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค
๊ทธ๋ž˜์„œ ์—…๋ฐ์ดํŠธ ์ฟผ๋ฆฌ๋ฅผ ์ผ์ผํžˆ ์“ธ ํ•„์š” ์—†์ด save ๋ฉ”์„œ๋“œ๋ฅผ ๋ถ€๋ฅด๋Š” ๊ฒƒ๋งŒ์œผ๋กœ๋„ ์—…๋ฐ์ดํŠธ๊นŒ์ง€ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค!!
์ผ๋ฐ˜ ๋ฐฉ์‹๊ณผ Put๋ฐฉ์‹ (Rest API) ๋ฐฉ์‹์€ ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•˜๋‚˜๋งŒ ์žˆ์Šต๋‹ˆ๋‹ค :D
๊ทธ๋Ÿผ ํ•จ๊ป˜ ๋ณด์‹œ์ฃ !

Service (Interface)

// Interface์— ์•„๋ž˜ ์ฝ”๋“œ ์ถ”๊ฐ€.
Long update(MemberDetailDTO memberDetailDTO);

ServiceImpl

@Override
public Long update(MemberDetailDTO memberDetailDTO) {
	// update ์ฒ˜๋ฆฌ ์‹œ save ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ
	// ๊ธฐ์กด์— ์žˆ๋Š” ์ •๋ณด๋ฉด ์•Œ์•„์„œ ์—…๋ฐ์ดํŠธ ์ฟผ๋ฆฌ ์ˆ˜ํ–‰
	// MemberDetailDTO -> MemberEntity๋กœ ๋ณ€ํ™˜ํ•ด์ค˜์•ผํ•จ.
	// ๋ฐ”๊พธ๊ณ ์ž ํ•˜๋Š” ๋Œ€์ƒ ํด๋ž˜์Šค์— ํ•ด๋‹น ๋ฉ”์„œ๋“œ๊ฐ€ ์ƒ์„ฑ๋˜์–ด์•ผํ•จ.
	MemberEntity memberEntity = MemberEntity.toUpdateMember(memberDetailDTO);
	Long memberId = mr.save(memberEntity).getId();
	return memberId;
}

์—ฌ๊ธฐ๊นŒ์ง€ ์ž˜ ์˜ค์…จ๋‹ค๋ฉด ์ˆ˜์ •๊นŒ์ง€๋Š” ๋ฌธ์ œ์—†์ด ์ž˜ ๋™์ž‘ํ• ๊ฒ๋‹ˆ๋‹ค.

๋งˆ์น˜๋ฉฐ

ํšŒ์›๊ด€๋ฆฌ ์˜ˆ์ œ๋ฅผ ์ž˜ ๋”ฐ๋ผ์˜ค์‹œ๋Š๋ผ ์ˆ˜๊ณ  ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค.
ํšŒ์›๊ด€๋ฆฌ ์˜ˆ์ œ1 ๋ถ€ํ„ฐ ์ด๋ ‡๊ฒŒ ๊ธธ์–ด์งˆ์ง€๋Š” ๋ชฐ๋ž์—ˆ๋Š”๋ฐ ์ด ๊ธ€์„ ๋ณด๊ณ ์žˆ๋‹ค๋ฉด ์ž˜ ๋”ฐ๋ผ์˜ค์‹ ๊ฑฐ๋ผ ๋ฏฟ์Šต๋‹ˆ๋‹ค :D
๋‹ค์Œ ์‹œ๊ฐ„์—๋Š” ํšŒ์›๊ด€๋ฆฌ ์˜ˆ์ œ์— ์“ด Test ์ฝ”๋“œ์— ๋Œ€ํ•ด ์•Œ์•„๋ณผ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค!
๋งŒ์•ฝ ๋” ์ถ”๊ฐ€๋˜๋Š” ๋‚ด์šฉ์ด ์žˆ๋‹ค๋ฉด ์ƒˆ๋กœ์šด ์ •๋ฆฌ๊ธ€์—์„œ ๋งŒ๋‚˜๋„๋ก ํ•ด์š”!!
๋‹ค์Œ ์‹œ๊ฐ„์— ๊ฑด๊ฐ•ํ•œ ๋ชจ์Šต์œผ๋กœ ๋งŒ๋‚˜์š” :D

profile
์ฆ๊ฒ๋‹ค!

0๊ฐœ์˜ ๋Œ“๊ธ€