์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 | 31 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[64] 230330 Spring: ํ์ ์์ธ ์ ๋ณด ๋ณด๋ ํ์ด์ง ๋ง๋ค๊ธฐ [K-๋์งํธ ํธ๋ ์ด๋ 64์ผ] ๋ณธ๋ฌธ
[64] 230330 Spring: ํ์ ์์ธ ์ ๋ณด ๋ณด๋ ํ์ด์ง ๋ง๋ค๊ธฐ [K-๋์งํธ ํธ๋ ์ด๋ 64์ผ]
yjyuwisely 2023. 3. 30. 10:49230329 Thu 64th class
Ch. 18 MVC ํจํด ๊ตฌํ
์ง๋: Ch. 18 MVC ํจํด ๊ตฌํ์ ๊ธฐ๋ฐํ ์์ฒด ์์
(๊ต์ฌ: ์ต๋ฒ๊ท ์ JSP 2.3 ์น ํ๋ก๊ทธ๋๋ฐ: ๊ธฐ์ด๋ถํฐ ์ค๊ธ๊น์ง, ์ ์: ์ต๋ฒ๊ท )
์ฑ
์์ ์ฝ๋: https://github.com/madvirus/jsp23
์ ์ ๋ธ๋ก๊ทธ: https://javacan.tistory.com/
์ค๋ ๋ฐฐ์ด ๊ฒ ์ค ๊ธฐ์ตํ ๊ฒ์ ์ ๋ฆฌํ๋ค.
void ํ์
์ ๋ฉ์๋๋ ๊ฐ์ ์ ๋ฌ ํ ์ ์๊ณ , ๋จ์ง ์ถ๋ ฅ๋ง ๊ฐ๋ฅํฉ๋๋ค.
์ฐธ๊ณ : https://cloudstudying.kr/questions/49
ํ๋ก ํธ์๋ ์์ญ์ servlet-context.xml
๋ฐฑ์๋ ์์ญ์ root-context.xml์ด ๋งก๋๋ค.
์ฝ๋) servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="org.hj.controller" />
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.support.StandardServletMultipartResolver">
</beans:bean>
</beans:beans>
์ฝ๋) root-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<!-- DBCP(DB Connection Pool) -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/sample?serverTimezone=Asia/Seoul"></property>
<property name="username" value="root"></property>
<property name="password" value="1234"></property>
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
<!-- Mybatis ๊ด๋ จ ์ค์ SessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<mybatis-spring:scan base-package="org.hj.mapper"/>
<context:component-scan base-package="org.hj.service"/>
</beans>
์ฒซ๋ฒ์งธ resources: xmlํ์ผ๋ค์ด ์๋ค. (select์ , insert์ ๋ฑ)
๋๋ฒ์งธ resources: ์ธ๋ถ css, jsํ์ผ ๋ฃ๋ ๊ณต๊ฐ
MySQL์ ๋ฐ์ดํฐ → LoginVO.java (์ปจํธ๋กค๋ฌ)๋ก ๊ฐ๋ค.
→ ์ฝ๋) LoginVo.java ์ผ๋ถ
package org.hj.model;
public class LoginVO {
private String id;
private String password;
private String addr;
private String phone;
private String email;
private String name;
private int age;
}
→ listDetail.jsp๋ก ๋์ด๊ฐ๋ค.
๋ฌธ์ ํ์ด๋ณด๊ธฐ)
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ด์ฉ์ ํ ๋๋ก
http://localhost:8081/list(ํ์๋ชฉ๋ก๋ฆฌ์คํธ)์์
1) ID๋ฅผ ํด๋ฆญํ๋ฉด ๊ทธ ํ์์ ์์ธ๋ด์ฉ์ ์ ์ ์๋ ํ๋ฉด์ผ๋ก ์ด๋ํจ๊ณผ
2) ๋์์ ์ ๋ณด๋ฅผ ์กฐํํ๊ณ (select ๊ฒฐ๊ณผ 1 ๊ฑด - login์ ์ฐธ๊ณ )
3) ๊ทธ ํ๋ฉด์ ์์ ๊ณผ ์ญ์ ๋ฒํผ์ ์์ฑํ์ฌ,
4) ์์ ๋ฐ
5) ์ญ์ (ํ์ ๊ฐ์
- insert๋ฅผ ์ฐธ์กฐ)๋ฅผ ํ๋๋ก ๊ตฌํํด๋ณด์ธ์.
์ฐธ๊ณ : https://doublesprogramming.tistory.com/91
์ฐธ๊ณ : https://yoonbitnara.github.io/spring/53/
LoginMapper.xml์์ <๋ฅผ ์น๋ฉด ์ธ ์ ์๋ ์ฝ๋๋ค์ด ๋์จ๋ค.
id ๊ฐ์ ๋๊ธฐ๊ธฐ
(๋ด๊ฐ ์ด ๊ฑด ๋ณ์๋ช
memlistDetail์ด๋ค. ์์
์์ memdetail๋ก ์)
ํ๋ฉด์ id
http://localhost:8081/listDetail?id=abcd
→ MemberController.java
memlistDetail()
→ ls.memlistDetail()
→ LoginService.java
public void memlistDetail();
→ LoginServiceImpl.java
public void memlistDetail(){
lm.memlistDetail()
}
→ LoginMapper.java
public void memlistDetail();
→ LoginMapper.xml
select *
from member
where id=#{id}
๋ฐ๋ ๋ฐฉํฅ์ผ๋ก๋ ๊ฐ๋ฅํ๋ค.
return์ ์ด์ฉํ๋ค.
LoginMapper.xml์ LoginVO(๋ชจ๋ธ)๊ฐ ๋์ด๊ฐ ๋
๋ค๋ฅธ ํ์ผ์ void ๋๋ฌธ์ return์ด ์ ๋๋ฏ๋ก ๋ค ๋ฐ๊ฟ์ผํ๋ค.
๋ ๊ฐ์ง ๋ฐฉ๋ฒ
1. form ํ๊ทธ๋ฅผ ์ด์ฉํ๋ค.
<form action="listDetail">
์์ด๋<input type="text" name="id>
</form>
2. a ํ๊ทธ ์ด์ฉํ๋ฉด ๋๋ค.
<a href="listDetail?id=์์ด๋๊ฐ">์์ด๋</a>
listDetail.jsp๋ก ๊ฐ๊ธฐ ์ ์ select๋ก ์์ด๋ ๊ฐ์ ๊ฐ์ ธ๊ฐ๋ค.
void add(int a){ //๋ฉ์๋ ์ ์ธ
}
add(10) //๋ฉ์๋ ํธ์ถ
์์ ํํ๋ ์๋์ ๊ฐ๋ค.
public void memlistDetail(String id);//[#๋ฉ์๋ ์ ์ธ#]
ls.memlistDetail(id);//[#๋ฉ์๋ ํธ์ถ#]
id๋ ๊ธฐ๋ณธํค์ด๋ฏ๋ก ์ค๋ณต ์ ๋๋ค. ํ ๊ฑด๋ง ๋์จ๋ค.
์ฝ๋ 1) list.jsp
<%@ 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 var="๋ณ์" items="์์ดํ
" -->
<c:forEach var="list" items="${memlist}"> <!-- ๋ฐ๋ณตํ๋ค. -->
<tr>
<td><a href="listDetail?id=${list.id}">${list.id}</a></td>
<!-- ๋ด๊ฐ ํ๋ฆฐ ๋ถ๋ถ: <a href="listDetail"> ์์ ?id=${list.id} ์ถ๊ฐํ๋ฉด id๊ฐ์ด listDetail.jsp๋ก ๋์ด๊ฐ๊ฒ ๋๋ค. -->
<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) listDetail.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>๊ฐ์ธ ํ์ ๊ด๋ฆฌ ์์ธ ํ์ด์ง</title>
</head>
<body>
<!-- DB ์์
์ ํด์ผํ๋ค. ์๋น์ค์ Mapper์ ๋ณด๋ด์ค๋ค. -->
<%-- ${listDetail} --%>
<a href="listDetail?id=${list.id}">์์ด๋</a>
<table border="1">
<tr>
<td>ID</td><td>${listDetail.id}</td>
</tr>
<tr>
<td>๋น๋ฐ๋ฒํธ</td><td>${listDetail.password}</td>
</tr>
<tr>
<td>์ฃผ์</td><td>${listDetail.addr}</td>
</tr>
<tr>
<td>ํฐ๋ฒํธ</td><td>${listDetail.phone}</td>
</tr>
<tr>
<td>์ด๋ฉ์ผ</td><td>${listDetail.email}</td>
</tr>
<tr>
<td>์ด๋ฆ</td><td>${listDetail.name}</td>
</tr>
<tr>
<td>์์ผ</td><td>${listDetail.age}</td>
</tr>
</table>
<form>
<input type="submit" value="์์ " formaction="modifyMember.jsp">
<input type="submit" value="์ญ์ " formaction="removeMember.jsp">
</form>
</body>
</html>
→ ์ฝ๋ 3) MemberController.java
package org.hj.controller;
import javax.servlet.http.HttpSession;
import org.apache.tomcat.util.net.openssl.ciphers.Authentication;
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.GetMapping;
//import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MemberController { //MVC์ค ์ปจํธ๋กค๋ฌ ์ญํ ์ ํ๋ค.
@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) //value:์์ฒญ๋ฐ์ url์ ์ค์ ํ๊ฒ ๋๋ค.
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 ๋ง๋ค์ด์ค๋ค. /WEB-INF/views/member/list.jsp
}
//๊ณผ์ : ๊ฐ์ธ ํ์ ์์ธ ์ ๋ณด ์กฐํ ํ์ด์ง
@RequestMapping(value = "/listDetail", method = RequestMethod.GET) //list.jsp์ <a>ํ๊ทธ์ ?์ ๋๊ณ ๊ฐ๋ ๊ฒ ์์ผ๋ฉด ๊ฐ์ด ๊ฐ๊ฒ ๋๋ค.
//public String memberDetail(String id) {//๋งค๊ฐ ๋ณ์๋ฅผ ๋๋ค.
public String memberDetail(LoginVO login, Model model) {
// ๋งค๊ฐ๋ณ์๋ฅผ (LoginVO login)๋ก๋ ํด๋ ๋๋ค (private String id๊ฐ ์ ์๋์ด์์ผ๋ฏ๋ก) //์ฒ์ ์๋ฌ ๋ฉ์์ง: ๋ฆฌํด์ด ์์ด์ผ ํ๋ค.
//ls.memlistDetail(id);//[#๋ฉ์๋ ํธ์ถ#]
model.addAttribute("listDetail", ls.memlistDetail(login));
return "member/listDetail"; // /WEB-INF/views/member/listDetail.jsp
}
//ํ์ ์ ๋ณด ์์ ๋ฐ ์ญ์
}
→ ์ฝ๋ 4) LoginService.java
package org.hj.service; //LoginService๋ ํจํค์ง ์์ ์๋ค.
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(); //๋น์๋๋ค.
//public LoginVO memlistDetail(String id);//[#๋ฉ์๋ ์ ์ธ#] //๋ฆฌํด ํ์
์ ๋ชจ๋ฅด๊ฒ ์ผ๋ฉด ์ฐ์ void๋ก ๋๋ค.
public LoginVO memlistDetail(LoginVO login);
}
→ ์ฝ๋ 5) LoginServiceImpl.java
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 { //LoginService๋ฅผ ๊ตฌํํ๋ค.
@Autowired
LoginMapper lm; //LoginMapper lm = new LoginMapper();
//#####์๋ก ์ถ๊ฐํจ#####
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();
}
//public LoginVO memlistDetail(String id) {
public LoginVO memlistDetail(LoginVO login) {
return lm.memlistDetail(login);//[#๋ฉ์๋ ํธ์ถ#]
}
}
→ ์ฝ๋ 6) LoginMapper.java
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();
//public LoginVO memlistDetail(String id);//[#๋ฉ์๋ ์ ์ธ#]
public LoginVO memlistDetail(LoginVO login);
}
→ ์ฝ๋ 7) LoginMapper.xml
<?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>
<!-- ๊ฐ์ธ ํ์ ์์ธ ์ ๋ณด ์กฐํ ํ์ด์ง -->
<select id="memlistDetail" resultType="org.hj.model.LoginVO"> <!-- select๋ ๊ฒฐ๊ณผ๋ฅผ org.hj.model.LoginVO ํด๋์ค์ ์ ์ฅํ๋ค. -->
select *
from member
where id=#{id} <!-- id๋ฅผ ๋๊ณ ์ค๋ ์์
์ด ํ์ํ๋ค. ๋ฉ์๋์ ๋งค๊ฐ๋ณ์๋ก ๊ฐ๋ฅํ๋ค. ์ด ๋ ๊ฐ์ง ๋ฐฉ๋ฒ: String id, LoginVO๋ก ๊ฐ์ ธ์ฌ ์ ์๋ค.-->
</select>
</mapper>
๊ฒฐ๊ณผ) ํ์ ๋ฆฌ์คํธ๋ก ๊ฐ๋ค.
์์ด๋๋ฅผ ํด๋ฆญํ๋ฉด URL์ ?id="์ ํํ ์์ด๋"๊ฐ ๋จ๊ณ ์์ธ ํ์ด์ง๊ฐ ๋ฌ๋ค.