Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[63] 230329 Spring: ํšŒ์› ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 63์ผ] ๋ณธ๋ฌธ

๐ŸŒณBootcamp Revision 2023โœจ/Spring Framework, Java

[63] 230329 Spring: ํšŒ์› ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 63์ผ]

yjyuwisely 2023. 3. 29. 12:46

230329 Wed 63rd class

Ch. 18 MVC ํŒจํ„ด ๊ตฌํ˜„
์ง„๋„: Ch. 18 MVC ํŒจํ„ด ๊ตฌํ˜„์— ๊ธฐ๋ฐ˜ํ•œ ์ž์ฒด ์ˆ˜์—… (๊ต์žฌ: ์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€, ์ €์ž: ์ตœ๋ฒ”๊ท )
์ฑ… ์˜ˆ์ œ ์ฝ”๋“œ: https://github.com/madvirus/jsp23
์ €์ž ๋ธ”๋กœ๊ทธ: https://javacan.tistory.com/

 

์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€ | ์ตœ๋ฒ”๊ท  - ๊ต๋ณด๋ฌธ๊ณ 

์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ: ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€ | [์ตœ๋ฒ”๊ท ์˜ JSP 2.3 ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ ๊ธฐ์ดˆ๋ถ€ํ„ฐ ์ค‘๊ธ‰๊นŒ์ง€]๋Š” JSP 2.3์˜ ์ƒˆ๋กœ์šด ํŠน์ง• ๋ฐ˜์˜๊ณผ JSP๋ฅผ ์ง€์›ํ•˜๋Š” ์š”์†Œ์ธ ์„œ๋ธ”๋ฆฟ๊ณผ ํ‘œํ˜„ ์–ธ์–ด ๋“ฑ์˜ ์ƒˆ๋กœ์šด

product.kyobobook.co.kr


์˜ค๋Š˜ ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๊ธฐ์–ตํ•  ๊ฒƒ์„ ์ •๋ฆฌํ–ˆ๋‹ค.


์•ž์—์„œ ๋ฐฐ์šด ๊ฒƒ

Presentation    Business    Persistence tier   DB
SpringMVC <---------------> Spring Core  <---------------> MyBatis <------------>  
  <-------------------------------------------------------------------------------------------------------------  
MemberController.
java
  LoginService.
java 
  LoginMapper
from
LoginServiceImpl.
java
   
๋ฉ”์„œ๋“œ
member();
memberPost();
--------------->
member
๋ฐ์ดํ„ฐ๋ฅผ ๋„˜๊ธด๋‹ค.
ls

๋ฉ”์„œ๋“œ

memreg();
login();
--------------->
member
๋ฐ์ดํ„ฐ๋ฅผ ๋„˜๊ธด๋‹ค.
lm

๋ฉ”์„œ๋“œ

memreg();
login();
   

๋ฐ์ดํ„ฐ์˜ ํ๋ฆ„

login.jsp: ๋ฐ์ดํ„ฐ 

-> MemberController.javamember -> member

-> LoginService.java์˜ member

-> LoginServiceImpl.java์˜ member from public LoginVO login (LoginVO member) -> return lm.login(member)


-> LoginMapper.java์˜ member from public LoginVO login(LoginVO member);


-> LoginMapper.xml์˜ <select>์˜ #{id}, #{password}๊ฐ€ ์ผ์น˜ํ•ด์•ผํ•œ๋‹ค.

๊ทธ ํ›„ MySql์˜ DB์— ์ €์žฅ๋œ๋‹ค.


ํšŒ์› ๊ด€๋ฆฌ ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ

ํšŒ์›์„ ๊ด€๋ฆฌํ•˜๋Š” ํ™”๋ฉด (๊ด€๋ฆฌ์ž์šฉ)
http://localhost:8081/list

id name
์ด๋ฆ„
birthday
์ƒ์ผ
gender
์„ฑ๋ณ„
email
์ด๋ฉ”์ผ
phone
ํฐ๋ฒˆํ˜ธ
           

์–ด๋–ค ํ™”๋ฉด์„ ๋งŒ๋“ค๊ฑด์ง€ ์ƒ๊ฐํ•ด๋ณด๊ณ , ์ฃผ์†Œ๋ฅผ ์ƒ๊ฐํ•ด๋ณด๊ณ , ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋งŒ๋“ค๊ณ , ํด๋”๋ช… ๋งŒ๋“ค๊ณ  ๋ฆฌํ„ดํ•œ๋‹ค.
ํด๋”๋ช… ์—†์œผ๋ฉด JSP ํŒŒ์ผ ์ด๋ฆ„์œผ๋กœ ๋ฆฌํ„ดํ•œ๋‹ค. 

ํ™”๋ฉด์—์„œ ๋˜์งˆ ๊ฒŒ ์—†์œผ๋ฉด ๋งค๊ฐœ ๋ณ€์ˆ˜ ๋น„์›Œ๋‘”๋‹ค. 


์ฝ”๋“œ) MemberController.java ์ผ๋ถ€

@Controller
public class MemberController {

	@Autowired
	LoginService ls; //LoginService ls = new LoginService(); ํด๋ž˜์Šค๋ฅผ new๋ฅผ ์จ์„œ ๊ฐ์ฒดํ™”ํ•œ ๊ฒƒ. 

	// ํšŒ์›๊ด€๋ฆฌํŽ˜์ด์ง€
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String mergerlist() { //์ฒ˜์Œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€: ๋ฆฌํ„ด์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
		return "member/list"; //memberํด๋”์˜ list.jsp ๋งŒ๋“ค์–ด์ค€๋‹ค.
	}
}

์‹คํ–‰๋˜์ž๋งˆ์ž select ํ•ด์•ผ ํ•œ๋‹ค. ๋‘ ํ™”๋ฉด์œผ๋กœ ๋‚˜๋ˆŒ ํ•„์š”๊ฐ€ ์—†๊ณ  (ex. ๋กœ๊ทธ์ธ, ๋กœ๊ทธ์ธ ์„œ๋ฒ„, ํšŒ์› ๊ฐ€์ž…, ํšŒ์› ๊ฐ€์ž… ์„œ๋ฒ„ ์ฝ”๋“œ)
๋ฐ”๋กœ DB ์—ฐ๊ฒฐํ•œ๋‹ค. 
(์•ž์—์„œ ํ•œ ๋ฒ„ํŠผ ํด๋ฆญ ํ›„ DB์—ฐ๊ฒฐ๊ณผ๋Š” ๋‹ค๋ฅด๋‹ค.)

ํฐ๋ฒˆํ˜ธ๋Š” int๋กœ ํ•˜๋ฉด ์•ž์˜ 0์ด ์‚ฌ๋ผ์ง€๋ฏ€๋กœ varchar๋กœ ํ•œ๋‹ค.


ArrayList
๋™์ ์ธ ๋ฐฐ์—ด์ด๋‹ค. (๊ธธ์ด๊ฐ€ ์™”๋‹ค๊ฐ”๋‹คํ•œ๋‹ค.)
์ •์ˆ˜ ๊ฐ’๋งŒ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.

ArrayList<Integer> score = new ArrayList<>();
score 10 20 30 40 50 60 70



์ •์‹ ๋ช…์นญ: ์ œ๋„ค๋ฆญ ํƒ€์ž…

ArrayList<LoginVO> score = new ArrayList<>();


์ œ๋„ค๋ฆญ(Generic)์€ ํด๋ž˜์Šค ๋‚ด๋ถ€์—์„œ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹Œ ์™ธ๋ถ€์—์„œ ์‚ฌ์šฉ์ž์— ์˜ํ•ด ์ง€์ •๋˜๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•œ๋‹ค.
์ฐธ๊ณ : https://st-lab.tistory.com/153

MySQL์— ์žˆ๋Š” ๊ฐ๊ฐ์˜ ํ–‰์ด ์ €์žฅ๋œ๋‹ค.
LoginVO ํƒ€์ž…์ด ์ €์žฅ๋œ๋‹ค.

public class LoginVO {

private String id; //aaaa
private String password; //1234
private String addr;
private String phone; //2023-03-29
private String email;
private String name; //์ •์ž๋ฐ”
private int age;
} //์—†๋Š” ๊ฒƒ์€ null๊ฐ’์ด ๋“ค์–ด๊ฐ„๋‹ค.
public class LoginVO {

private String id;
private String password;
private String addr;
private String phone;
private String email;
private String name;
private int age;
}
public class LoginVO {

private String id;
private String password;
private String addr;
private String phone;
private String email;
private String name;
private int age;
}
score[0] score[1] (๊ฐ๊ฐ ๋‹ค๋ฅธ ๊ฐ’) score[2] (๊ฐ๊ฐ ๋‹ค๋ฅธ ๊ฐ’) ...
์ญ‰ ๋‚˜๊ฐ  score[n]

๋ฆฌํ„ดํ•ด์„œ ๊ฐ€์ ธ๊ฐ„๋‹ค.


๋ฐ์ดํ„ฐ์˜ ํ๋ฆ„

ํ๋ฆ„ ์ˆœ์„œ๋Š” ์ขŒ์ธก ์ƒ๋‹จ, ๊ทธ ์•„๋ž˜, ์ค‘๊ฐ„, ๊ทธ ์•„๋ž˜, ์šฐ์ธก ์ƒ๋‹จ, ๊ทธ ์•„๋ž˜ ์ˆœ์„œ์ด๋‹ค.
์ฒ˜์Œ์— ์˜ค๋ฅ˜๊ฐ€ ๋‚ฌ์—ˆ๋Š”๋ฐ ์•„๋ž˜ ํŒŒ์ผ์— LoginVO ํƒ€์ž…๋กœ ์„ค์ •์„ ์•ˆ ํ•ด์„œ ๊ทธ๋ ‡๋‹ค.
LoginService.java

LoginServiceImpl.java

LoginMapper.java

[1] list.jsp: ๋ฐ์ดํ„ฐ
(board/list.jsp : ๊ฒŒ์‹œํŒ ๋ชฉ๋ก์ด๋ฉฐ, member/list.jsp : ํšŒ์› ๋ชฉ๋ก์œผ๋กœ ๋‹ค๋ฅด๋‹ค.) 

์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฐ์ดํ„ฐ๋ฅผ .jsp๋กœ ๋ณด๋‚ผ ๋•Œ ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฐฉ์‹์œผ๋กœ ๋ชจ๋ธ์„ ์“ด๋‹ค.
์ฝ”๋“œ) BoardController.java

// ๊ฒŒ์‹œํŒ ์ƒ์„ธ ํŽ˜์ด์ง€
	@RequestMapping(value = "/board/detail", method = RequestMethod.GET)
	// public String detail(int bno){
	public String detail (BoardVO board, Model model) {
		System.out.println(board);
		// bs.detail(bno);
		model.addAttribute("detail", bs.detail(board));
		return "board/detail";
	}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>     
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํšŒ์› ๊ด€๋ฆฌ ํŽ˜์ด์ง€</title>
</head>
<body>
${memlist}
	<table border="1">
	<tr>
		<td>ID</td><td>๋น„๋ฐ€๋ฒˆํ˜ธ</td><td>์ฃผ์†Œ</td><td>ํฐ๋ฒˆํ˜ธ</td><td>์ด๋ฉ”์ผ</td><td>์ด๋ฆ„</td><td>์ƒ์ผ</td>
	</tr>
	<c:forEach items="${memlist}" var="list">
		<tr>
		<td>${list.id}</td>
		<td>${list.password}</td>
		<td>${list.addr}</td>
		<td>${list.phone}</td>
		<td>${list.email}</td>
		<td>${list.name}</td>
		<td>${list.age}</td>
	</tr>
	</c:forEach> <!-- ๋ฐ˜๋ณตํ•œ๋‹ค. -->
	</table>
</body>
</html>


[2] MemberController.javamember -> member

package org.hj.controller;

import javax.servlet.http.HttpSession;

import org.hj.model.LoginVO; //๋ชจ๋ธ(LoginVO)์ด ์žˆ์Œ์„ ์•Œ๋ ค์ค€๋‹ค.
import org.hj.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class MemberController {

	@Autowired
	LoginService ls; //LoginService ls = new LoginService(); ํด๋ž˜์Šค๋ฅผ new๋ฅผ ์จ์„œ ๊ฐ์ฒดํ™”ํ•œ ๊ฒƒ. 
	//LoginService๋Š” ์ธํ„ฐํŽ˜์ด์Šค์ด๋ฏ€๋กœ ์›๋ž˜ new๋Š” ์•ˆ ๋˜๋Š” ๋ฐ ์œ„์— @AutoWired ์ด์šฉํ•ด์„œ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ–ˆ๋‹ค.
	
	// ํšŒ์›๊ฐ€์ž… //ํ™”๋ฉด ์‹คํ–‰์„ ์œ„ํ•œ ๋ฉค๋ฒ„ (GET๋ฐฉ์‹)
	@RequestMapping(value = "/member", method = RequestMethod.GET) //member ๋ฉ”์„œ๋“œ GET ๋ฐฉ์‹
	public String member () {
		return "member/memberin"; //๋ฉค๋ฒ„ ํด๋”์˜ memberin.jsp๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.
	}
	
	// ํšŒ์›๊ฐ€์ž…์„œ๋ฒ„ //์‹ค์ œ๋กœ ๊ฐ€์ž…ํ•˜๊ธฐ ์œ„ํ•œ ๋ฉค๋ฒ„ (POST๋ฐฉ์‹)
	@RequestMapping(value = "/member", method = RequestMethod.POST) //๋‘˜ ๋‹ค GET์ด๋ฉด ์ถฉ๋Œ์ด ์ผ์–ด๋‚œ๋‹ค. ๋ฉ”์„œ๋“œ ๋ฐฉ์‹์ด POST์ด๋‹ค.
	//							int		a //member๋Š” ์ฐธ์กฐ ๋ณ€์ˆ˜
	//public String memberPost(String id, String password, String name) //๋ฉ”๋ชจ๋ฆฌ ์ฐจ์ง€๊ฐ€ ํฌ๋ฏ€๋กœ ์“ฐ์ง€ ์•Š๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. private ๊ฐ™์€ ์ ‘๊ทผ ์ œํ•œ์ž๋„ ์—†๋‹ค.
	public String memberPost (LoginVO member) { // ๋ชจ๋ธ: LoginVO
		System.out.println(member); //member.toString()์ด ์ƒ๋žต๋œ ๊ฒƒ์ด๋‹ค.
		//#####์ƒˆ๋กœ ์ถ”๊ฐ€ํ•จ#####
		ls.memreg(member);
		return "board/list"; //board ํด๋”์˜ list.jsp๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. ๊ฒŒ์‹œํŒ ๋ชฉ๋ก์„ ๋ณด์—ฌ์ค€๋‹ค.
	}
	
	
	
	
	// ๋กœ๊ทธ์ธ ํŽ˜์ด์ง€
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login () {
		System.out.println("aaaa");
		return "member/login";
	}
	
	// ๋กœ๊ทธ์ธ ์„œ๋ฒ„
	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String loginPost (HttpSession session, LoginVO member) { //member: login.jsp์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.
		// HttpSession session = new HttpSession; ์œ„ ()์•ˆ์˜ HttpSession session์„ ์ง€์šฐ๊ณ  ๋Œ€์‹  ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.
/*		System.out.println("contorller="+member);
		System.out.println(ls.login(member));*/
		
		session.setAttribute("login", ls.login(member)); //์œ„ member์˜ ์•„์ด๋””, ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๊ฐ€์ ธ๊ฐ„๋‹ค.
		
		if (ls.login(member)==null) {
			return "member/login";
			} else {
				session.setAttribute("login", ls.login(member)); //null์ด ์•„๋‹ˆ๋ฉด ์„ธ์…˜์— ์ €์žฅํ•œ๋‹ค.
				return "redirect:/list"; 
				//์œ„๋Š” ์ฃผ์†Œ ์ •์˜ํ•ด์ค€ ๊ฒŒ ์—†์–ด์„œ ์ฒ˜์Œ์— ์—๋Ÿฌ๋‚จ (board์˜ list.jsp๋กœ ๊ฐ€๋Š” ๊ฒŒ ์•„๋‹Œ ๋“ฏ -> member ํด๋”์˜ list.jsp ๋”ฐ๋กœ ๋งŒ๋“ค์–ด์•ผํ•œ๋‹ค.)
				//return "/board/list"; //๊ฒŒ์‹œํŒ ๋ฆฌ์ŠคํŠธ ๋ณด๊ธฐ ์œ„ํ•ด ๋‚ด๊ฐ€ ์•„๋ž˜ ์ฝ”๋“œ๋กœ ๋ฐ”๊ฟˆ. 
			}
		}
	
	// ํšŒ์›๊ด€๋ฆฌํŽ˜์ด์ง€
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String mergerlist(Model model) { //์ฒ˜์Œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€: ๋ฆฌํ„ด์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
		//model.addAttribute(String name, Object value);
		//: value ๊ฐ์ฒด๋ฅผ name ์ด๋ฆ„์œผ๋กœ ์ถ”๊ฐ€ํ•จ. ๋ทฐ ์ฝ”๋“œ์—์„œ๋Š” name์œผ๋กœ ์ง€์ •ํ•œ ์ด๋ฆ„์„ ํ†ตํ•ด์„œ value๋ฅผ ์‚ฌ์šฉํ•จ.
		model.addAttribute("memlist", ls.memlist()); //ls.memlist()->memlist:๋ฐ์ดํ„ฐ ์ €์žฅํ•ด์„œ ๋„˜๊ธด๋‹ค.
		return "member/list"; //memberํด๋”์˜ list.jsp ๋งŒ๋“ค์–ด์ค€๋‹ค.
	}
	// ํšŒ์›์ •๋ณด์ˆ˜์ • ๋ฐ ์‚ญ์ œ
	
}



[3] LoginService.java์˜ member

public void memlist(); //๋น„์›Œ๋‘”๋‹ค.
package org.hj.service;

import java.util.ArrayList;

import org.hj.model.LoginVO;
//์„ค๊ณ„ํ•œ๋‹ค.
public interface LoginService { //์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ new()๋ฅผ ํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ MemberController.java์— @Autowired๋ฅผ ์„ค์ •
	//#####์ƒˆ๋กœ ์ถ”๊ฐ€ํ•จ#####
	public void memreg(LoginVO member); //์ถ”์ƒ๋ฉ”์„œ๋“œ์ด๋ฏ€๋กœ LoginServiceImpl.java์—์„œ ๊ตฌํ˜„ํ•œ๋‹ค.
	public LoginVO login(LoginVO member);
	public ArrayList<LoginVO> memlist(); //๋น„์›Œ๋‘”๋‹ค.
	
}



[4] LoginServiceImpl.java์˜ member from public LoginVO login (LoginVO member) -> return lm.login(member)

LoginServiceImpl.java

	public void memlist() {
		
		lm.memlist();
		
	}

์œ„์˜ ์ฝ”๋“œ๊ฐ€ ์•„๋ž˜ MemberController.java์˜ ls.memlist();๋กœ ๊ฐ„๋‹ค.

	// ํšŒ์›๊ด€๋ฆฌํŽ˜์ด์ง€
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String mergerlist() { //์ฒ˜์Œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€: ๋ฆฌํ„ด์ด ์žˆ์–ด์•ผ ํ•œ๋‹ค.
    	ls.memlist();
		return "member/list"; //memberํด๋”์˜ list.jsp ๋งŒ๋“ค์–ด์ค€๋‹ค.
	}
package org.hj.service;

import java.util.ArrayList;

import org.hj.mapper.LoginMapper;
import org.hj.model.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
//๊ตฌํ˜„ํ•œ๋‹ค.
@Service
public class LoginServiceImpl implements LoginService {
	
	@Autowired
	LoginMapper lm;
	
	//#####์ƒˆ๋กœ ์ถ”๊ฐ€ํ•จ#####
	public void memreg(LoginVO member) { //์ถ”์ƒ๋ฉ”์„œ๋“œ LoginSerive.java๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.
		lm.memreg(member);
	};
	
	public LoginVO login (LoginVO member) {
		System.out.println("service="+member);
		System.out.println("service return="+lm.login(member));
		return lm.login(member);
	}
//๋น„์ฆˆ๋‹ˆ์Šค๊นŒ์ง€ ๋๋‚ฌ๋‹ค. ์„œ๋น„์Šค -> DB ์—ฐ๊ฒฐํ•ด์•ผํ•œ๋‹ค.	
	public ArrayList<LoginVO> memlist() {
		
		return lm.memlist();
		
	}
}



[5] LoginMapper.java์˜ member from public LoginVO login(LoginVO member);

package org.hj.mapper;

import java.util.ArrayList;

import org.hj.model.LoginVO;

public interface LoginMapper {
	//#####์ƒˆ๋กœ ์ถ”๊ฐ€ํ•จ#####
	public void memreg(LoginVO member);
	public LoginVO login(LoginVO member);
	public ArrayList<LoginVO> memlist();
}



[6] LoginMapper.xml์˜ <select>์˜ #{id}, #{password}๊ฐ€ ์ผ์น˜ํ•ด์•ผํ•œ๋‹ค.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

  
  <mapper namespace="org.hj.mapper.LoginMapper">
  
  <!-- #####์ƒˆ๋กœ ์ถ”๊ฐ€ํ•จ##### -->
	<insert id="memreg"> <!-- LoginMapper.java์˜ memreg๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค. insertํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.-->
  		insert into member (id, password, name, birthday, gender)
  		values(#{id},#{password},#{name},sysdate(),"f");
	</insert>
  
  	
	<select id="login" resultType="org.hj.model.LoginVO"> <!-- ๊ตฌํ˜„๋ฉ”์„œ๋“œ๊ฐ€ ์—†์œผ๋‹ˆ๊นŒ return์ด ์—†๋‹ค. -->
	<!-- ๋Œ€์‹  select๋Š” resultType์ด๋ผ๋Š” ํƒ€์ž…์ด return ์—ญํ• ์ด๋‹ค. -->
  		select id, password <!-- ๊ฒฐ๊ณผ๋Š” ํ•œ ๊ฑด์ด๋‹ค. id๋Š” ๊ธฐ๋ณธํ‚ค์ด๋‹ค. -->
  		from member
  		where id=#{id} and password=#{password}
	</select>
  	
  	<!-- ํšŒ์› ๊ด€๋ฆฌ ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€ -->
  	<select id="memlist" resultType="org.hj.model.LoginVO">
  	
  		select * from member <!-- ๊ฒฐ๊ณผ๋Š” ์—ฌ๋Ÿฌ ๊ฑด์ด๋‹ค. LoginVOํƒ€์ž…์˜ ๋ฐฐ์—ด์ด ํ•„์š”ํ•˜๋‹ค!-->
  		  		
  	</select>
  </mapper>



๊ทธ ํ›„ MySql์˜ DB์— ์ €์žฅ๋œ๋‹ค.

๊ฒฐ๊ณผ)


728x90
๋ฐ˜์‘ํ˜•
Comments