<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 align="center">이미지 입력</h3>
<form action="membersave" method="post" enctype="multipart/form-data">
<table border="1" align="center">
<tr>
<th>아이디</th>
<td><input type="text" name="id"></td>
</tr>
<tr>
<th>비밀번호</th>
<td><input type="text" name="pw"></td>
</tr>
<tr>
<th>이름</th>
<td><input type="text" name="name"></td>
</tr>
<tr>
<th>주민번호</th>
<td><input type="text" name="jumin"></td>
</tr>
<tr>
<th>전화번호</th>
<td><input type="text" name="phone"></td>
</tr>
<tr>
<th>주소</th>
<td><input type="text" name="address"></td>
</tr>
<tr>
<th>파일</th>
<td><input type="file" name="picture"></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="회원가입">
<input type="reset" value="취소">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ 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>Insert title here</title>
</head>
<body>
<h3 align="center">이미지 출력</h3>
<table border="1" align="center" width="600px">
<tr>
<th>아이디</th><th>이름</th><th>나이</th><th>성별</th>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td>
<a href="memberout2?id=${list.id}">
${list.id}</a>
</td>
<td>${list.name}</td>
<td>${list.age}</td><td>${list.gender}</td>
</tr>
</c:forEach>
<tr style="border-left: none;border-right: none;border-bottom: none">
<td colspan="4" style="text-align: center;">
<c:if test="${paging.startPage !=1}">
<a href="memberout?nowPage=${paging.startPage-1}&cntPerPage=${paging.cntPerPage}">◀</a>
</c:if>
<c:forEach begin="${paging.startPage}" end="${paging.endPage}" var="p">
<c:choose>
<c:when test="${p == paging.nowPage}">
<b><span style="color:red;font-family:bold">${p}</span></b>
</c:when>
<c:when test="${p != paging.nowPage}">
<a href="memberout?nowPage=${p}&cntPerPage=${paging.cntPerPage}">${p}</a>
</c:when>
</c:choose>
</c:forEach>
<c:if test="${paging.endPage != paging.lastPage}">
<a href="memberout?nowPage=${paging.endPage+1}&cntPerPage=${paging.cntPerPage}">▶</a>
</c:if>
</td>
</tr>
</table>
</body>
</html>
<%@ 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>Insert title here</title>
</head>
<body>
<h3 align="center">이미지 출력2</h3>
<table border="1" align="center" width="800px">
<tr>
<th>아이디</th><th>이름</th><th>전화번호</th><th>주소</th>
<th>이미지</th>
</tr>
<tr>
<td>${dto.id}</td><td>${dto.name}</td>
<td>${dto.phone}</td><td>${dto.address}</td>
<td>
<img src="resources/${dto.picture}" width="150px" height="120px">
</td>
</tr>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/views/layout.jsp">
<put-attribute name="title" value=""/>
<put-attribute name="top" value="/WEB-INF/views/top.jsp"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
</definition>
<definition name="main" extends="baseLayout">
<put-attribute name="title" value="메인화면"/>
<put-attribute name="body" value="/WEB-INF/views/main.jsp"/>
</definition>
<definition name="memberinput" extends="baseLayout">
<put-attribute name="title" value="회원가입폼"/>
<put-attribute name="body" value="/WEB-INF/views/member/memberinput.jsp"/>
</definition>
<definition name="memberoutput" extends="baseLayout">
<put-attribute name="title" value="회원출력폼"/>
<put-attribute name="body" value="/WEB-INF/views/member/memberoutput.jsp"/>
</definition>
<definition name="memberoutput2" extends="baseLayout">
<put-attribute name="title" value="회원출력폼2"/>
<put-attribute name="body" value="/WEB-INF/views/member/memberoutput2.jsp"/>
</definition>
</tiles-definitions>
package com.ezen.kim16_001.member;
public class MemberDTO {
String id,pw,name,jumin,phone,address,picture;
int age;
String gender;
public MemberDTO() {
}
public MemberDTO(String id, String pw, String name, String jumin, String phone, String address, String picture,
int age, String gender) {
super();
this.id = id;
this.pw = pw;
this.name = name;
this.jumin = jumin;
this.phone = phone;
this.address = address;
this.picture = picture;
this.age = age;
this.gender = gender;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPw() {
return pw;
}
public void setPw(String pw) {
this.pw = pw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getJumin() {
return jumin;
}
public void setJumin(String jumin) {
this.jumin = jumin;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPicture() {
return picture;
}
public void setPicture(String picture) {
this.picture = picture;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
}
package com.ezen.kim16_001.member;
import java.util.ArrayList;
public interface Service1 {
public void insert(String id,String pw,String name,String jumin,String phone,String address,String fname);
public int cntnotice();
public ArrayList<MemberDTO> out(PageDTO dto);
public MemberDTO out2(String id);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ezen.kim16_001.member.Service1">
<insert id="insert">
insert into db03141 values (#{param1},#{param2},#{param3},#{param4},#{param5},#{param6},#{param7})
</insert>
<select id="cntnotice" resultType="int">
select count(*) from db03141
</select>
<select id="out" resultType="com.ezen.kim16_001.member.MemberDTO">
select * from (
select rownum rn,A.* from(
select * from DB03141)A)
where rn between #{start} AND #{end}
</select>
<select id="out2" resultType="com.ezen.kim16_001.member.MemberDTO">
select * from db03141 where id = #{param1}
</select>
</mapper>
package com.ezen.kim16_001.member;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.servlet.http.HttpServletRequest;
import org.apache.ibatis.session.SqlSession;
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.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
@Controller
public class MemberController {
@Autowired
SqlSession sqlsession;
@RequestMapping(value="/memberin")
public String ko1() {
return "memberinput";
}
@RequestMapping(value="/membersave")
public String ko2(MultipartHttpServletRequest mul) throws Exception {
String id = mul.getParameter("id");
String pw = mul.getParameter("pw");
String name = mul.getParameter("name");
String jumin = mul.getParameter("jumin");
String phone = mul.getParameter("phone");
String address = mul.getParameter("address");
MultipartFile mf = mul.getFile("picture");
String fname = mf.getOriginalFilename();
String path = "C:\\12월국비\\spring\\day16_001\\src\\main\\webapp\\resources";
mf.transferTo(new File(path,fname));
Service1 ss1 = sqlsession.getMapper(Service1.class);
ss1.insert(id,pw,name,jumin,phone,address,fname);
return "redirect:memberin";
}
@RequestMapping(value="/memberout")
public String ko3(HttpServletRequest request,PageDTO dto,Model mo) {
String nowPage = request.getParameter("nowPage");
String cntPerPage = request.getParameter("cntPerPage");
Service1 ss1 = sqlsession.getMapper(Service1.class);
int total = ss1.cntnotice();
if(nowPage==null && cntPerPage == null) {
nowPage="1";
cntPerPage="5";
}
else if(nowPage==null) {
nowPage="1";
}
else if(cntPerPage==null) {
cntPerPage="5";
}
dto = new PageDTO(total,Integer.parseInt(nowPage),Integer.parseInt(cntPerPage));
mo.addAttribute("paging", dto);
ArrayList<MemberDTO> list = ss1.out(dto);
for(int i=0;i<list.size();i++) {
String jumin = list.get(i).getJumin();
int jumincheck = Integer.parseInt(jumin.substring(7,8));
int juminyear = Integer.parseInt(jumin.substring(0,2));
if(jumincheck==1 || jumincheck==2) {
juminyear=juminyear+1900;
}
else {
juminyear=juminyear+2000;
}
GregorianCalendar gc = new GregorianCalendar();
int nowyear = gc.get(Calendar.YEAR);
int age = nowyear-juminyear+1;
String gender = null;
if(jumincheck==1 || jumincheck==3) {
gender="남";
}
else {
gender="여";
}
list.get(i).setGender(gender);
list.get(i).setAge(age);
}
mo.addAttribute("list", list);
return "memberoutput";
}
@RequestMapping(value="/memberout2")
public String ko4(HttpServletRequest request,Model mo) {
String id = request.getParameter("id");
Service1 ss1 = sqlsession.getMapper(Service1.class);
MemberDTO dto = ss1.out2(id);
mo.addAttribute("dto", dto);
return "memberoutput2";
}
}
'SPRING' 카테고리의 다른 글
230316_게시판 (0) | 2023.03.16 |
---|---|
230315_게시판 (0) | 2023.03.15 |
230313_게시판 (0) | 2023.03.13 |
230310_AJAX (0) | 2023.03.10 |
230309_AJAX (0) | 2023.03.09 |
댓글