<DAO.java>
package com.smhrd.model;
import java.util.ArrayList;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.smhrd.database.SqlSessionManager;
public class DAO {
private SqlSessionFactory sqlSessionFactory = SqlSessionManager.getSqlSession();
private SqlSession sqlSession = null;
public int join(MemberVO vo) {
int row = 0;
try {
sqlSession= sqlSessionFactory.openSession(true);
row = sqlSession.insert("com.smhrd.model.DAO.memberinsert", vo);
}catch (Exception e) {
e.printStackTrace();
}finally {
sqlSession.close();
}
return row;
}
public MemberVO login(MemberVO vo) {
MemberVO result = null;
try {
sqlSession = sqlSessionFactory.openSession(true);
result = sqlSession.selectOne("com.smhrd.model.DAO.memberlogin", vo);
}catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return result;
}
// 회원정보수정 메소드
public int update(MemberVO vo) {
int row= 0;
try {
sqlSession = sqlSessionFactory.openSession(true);
row = sqlSession.update("com.smhrd.model.DAO.memberupdate", vo);
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return row;
}
// 회원관리 메소드
@SuppressWarnings({"unchecked", "rawtypes"})
public ArrayList<MemberVO> showMember() {
ArrayList<MemberVO> list = new ArrayList<MemberVO>();
try {
sqlSession = sqlSessionFactory.openSession(true);
list = (ArrayList)sqlSession.selectList("com.smhrd.model.DAO.memberselect");
} catch (Exception e) {
e.printStackTrace();
} finally {
sqlSession.close();
}
return list;
}
}
<MemberMapper.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="com.smhrd.model.DAO" >
<insert id="memberinsert" parameterType="MemberVO">
<!-- 테이블 명칭 주의하기! -->
insert into message values(#{email},#{pw},#{phone},#{address})
<!-- MemberVO.java에 있는 필드명임 -->
</insert>
<select id="memberlogin" parameterType="MemberVO" resultType="MemberVO">
select email,phone,address from message where email = #{email} and pw = #{pw}
</select>
<update id="memberupdate" parameterType="MemberVO">
update message set pw=#{pw}, phone=#{phone}, address=#{address} where email=#{email}
</update>
<select id="memberselect" resultType="MemberVO">
select * from message
</select>
</mapper>
<select.jsp>
<%@page import="com.smhrd.model.MemberVO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.smhrd.model.DAO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 1.request영역에 저장된 정보를 가져오시오. -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Forty by HTML5 UP</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assets/css/main.css" />
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
</head>
<style>
<%
DAO dao = new DAO();
ArrayList<MemberVO> list = dao.showMember();
%>
</style>
<body style="text-align: center;">
<!-- Wrapper -->
<div id="wrapper">
<!-- Menu -->
<nav id="Update">
<table>
<caption><h2>회원관리페이지</h2></caption>
<tr>
<td>Email</td>
<td>Tel</td>
<td>Address</td>
</tr>
<!-- 2.모든 회원의 이메일(email),전화번호(tel),주소(address)를 출력하시오. -->
<!-- 1) for each문 사용 -->
<%for(MemberVO vo : list){ %>
<tr>
<td><%=vo.getEmail() %></td>
<td><%=vo.getPhone() %></td>
<td><%=vo.getAddress() %></td>
</tr>
<%} %>
<!--2) for문 이용한 방법
<%for(int i=0; i<list.size();i++){%>
<tr>
<td><%=list.get(i).getEmail() %></td>
<td><%=list.get(i).getPhone() %></td>
<td><%=list.get(i).getAddress()%></td>
</tr>
<%}%> -->
</table>
</nav>
<a href="main.jsp" class="button next scrolly">되돌아가기</a>
</div>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.scrolly.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>
'Maven Project' 카테고리의 다른 글
JSTL 사용법 (0) | 2022.05.25 |
---|---|
회원관리삭제 (0) | 2022.05.25 |
Update 실습 (0) | 2022.05.25 |
로그인 실습 (0) | 2022.05.18 |
회원가입 실습 (0) | 2022.05.18 |