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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | package com.lat.beans; import java.sql.Date; public class Member_AttachFile { private String id; private long file_idx; private String origine; private String attach; private long file_size; private String path; private String file_type; private Date reg_date; public String getId() { return id; } public void setId(String id) { this.id = id; } public long getFile_idx() { return file_idx; } public void setFile_idx(long file_idx) { this.file_idx = file_idx; } public String getOrigine() { return origine; } public void setOrigine(String origine) { this.origine = origine; } public String getAttach() { return attach; } public void setAttach(String attach) { this.attach = attach; } public long getFile_size() { return file_size; } public void setFile_size(long file_size) { this.file_size = file_size; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getFile_type() { return file_type; } public void setFile_type(String file_type) { this.file_type = file_type; } public Date getReg_date() { return reg_date; } public void setReg_date(Date reg_date) { this.reg_date = reg_date; } } | cs |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | package com.lat.controller; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; 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; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; import com.lat.beans.Member_AttachFile; import com.lat.dao.Member_AttachFileDAOService; @Controller public class Member_AttachFileController { @Autowired private Member_AttachFileDAOService member_AttachFileDAOService; @RequestMapping(value="/member_AttachFile/listMember_AttachFile") public ModelAndView list(HttpServletRequest request){ List<Member_AttachFile> list=member_AttachFileDAOService.listMember_AttachFile(); return new ModelAndView("member_AttachFile/listMember_AttachFile","list",list); } @RequestMapping(value="/member_AttachFile/insertMember_AttachFile") public ModelAndView insertReward(HttpServletRequest request){ return new ModelAndView("member_AttachFile/insertMember_AttachFile"); } @RequestMapping(value="/member_AttachFile/insert", method=RequestMethod.POST) public String listMember_AttachFile(HttpServletRequest request,MultipartHttpServletRequest multiRequest, Model model){ Map map = new HashMap(); try{ map = uploadByMultipartHttpServletRequest(multiRequest , model); }catch(Exception e){ System.out.println(e.toString()); } String id=request.getParameter("id"); String file_idx=request.getParameter("file_idx"); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss"); Date date = new Date(); String attach=format.format(date).toString(); Member_AttachFile member_AttachFile=new Member_AttachFile(); member_AttachFile.setId(id); member_AttachFile.setFile_idx(Long.parseLong(file_idx)); member_AttachFile.setOrigine((String)map.get("fileName")); member_AttachFile.setAttach(attach); member_AttachFile.setFile_size((Long)map.get("filesize")); member_AttachFile.setPath((String)map.get("uploadPath")); member_AttachFile.setFile_type((String)map.get("filetype")); member_AttachFileDAOService.insertMember_AttachFile(member_AttachFile); return "redirect:listMember_AttachFile"; } @RequestMapping(value="/member_AttachFile/detailMember_AttachFile", method=RequestMethod.GET) public ModelAndView detailMember_AttachFile(HttpServletRequest request){ String id=request.getParameter("num"); Member_AttachFile member_AttachFile=new Member_AttachFile(); member_AttachFile.setId(id); ModelAndView result = new ModelAndView(); Member_AttachFile member_AttachFileRlt=member_AttachFileDAOService.detailMember_AttachFile(member_AttachFile); result.addObject("member_AttachFile", member_AttachFileRlt); result.setViewName("member_AttachFile/detailMember_AttachFile"); return result; } @RequestMapping(value="/member_AttachFile/multipartHttpServletRequest", method=RequestMethod.POST) public Map uploadByMultipartHttpServletRequest(MultipartHttpServletRequest multiRequest, Model model) throws IOException { MultipartFile multipartFile = multiRequest.getFile("f"); Map map=new HashMap(); if(!multipartFile.isEmpty()){ File file = new File("D:/uploadMember_AttachFile", multipartFile.getOriginalFilename()); multipartFile.transferTo(file); map.put("title", multiRequest.getParameter("title")); map.put("fileName", multipartFile.getOriginalFilename()); map.put("filesize", multipartFile.getSize()); map.put("filetype", multipartFile.getContentType()); map.put("uploadPath", file.getAbsolutePath()); } return map; } @RequestMapping(value="/member_AttachFile/delete", method=RequestMethod.POST) public String deleteMember_AttachFile(HttpServletRequest request){ String id=request.getParameter("id"); Member_AttachFile member_AttachFile=new Member_AttachFile(); member_AttachFile.setId(id); member_AttachFileDAOService.deleteMember_AttachFile(member_AttachFile); return "redirect:listMember_AttachFile"; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | package com.lat.dao; import java.util.List; import com.lat.beans.Member_AttachFile; public interface Member_AttachFileDAO { public List<Member_AttachFile> listMember_AttachFile(); public void insertMember_AttachFile(Member_AttachFile member_AttachFile); public Member_AttachFile detailMember_AttachFile(Member_AttachFile member_AttachFile); public void deleteMember_AttachFile(Member_AttachFile member_AttachFile); } | cs |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 | package com.lat.dao; import java.util.List; import org.apache.ibatis.session.SqlSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; import com.lat.beans.Member_AttachFile; @Repository public class Member_AttachFileDAOService implements Member_AttachFileDAO { @Autowired private SqlSession sqlSession; @Override public void insertMember_AttachFile(Member_AttachFile member_AttachFile) { // TODO Auto-generated method stub Member_AttachFileMapper member_AttachFileMapper = sqlSession.getMapper(Member_AttachFileMapper.class); member_AttachFileMapper.insertMember_AttachFile(member_AttachFile); } @Override public List<Member_AttachFile> listMember_AttachFile() { // TODO Auto-generated method stub Member_AttachFileMapper member_AttachFileMapper = sqlSession.getMapper(Member_AttachFileMapper.class); return member_AttachFileMapper.listMember_AttachFile(); } @Override public Member_AttachFile detailMember_AttachFile(Member_AttachFile member_AttachFile) { // TODO Auto-generated method stub Member_AttachFileMapper member_AttachFileMapper = sqlSession.getMapper(Member_AttachFileMapper.class); return member_AttachFileMapper.detailMember_AttachFile(member_AttachFile); } @Override public void deleteMember_AttachFile(Member_AttachFile member_AttachFile) { // TODO Auto-generated method stub Member_AttachFileMapper member_AttachFileMapper = sqlSession.getMapper(Member_AttachFileMapper.class); member_AttachFileMapper.deleteMember_AttachFile(member_AttachFile); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | package com.lat.dao; import java.util.List; import com.lat.beans.Member_AttachFile; public interface Member_AttachFileMapper { public List<Member_AttachFile> listMember_AttachFile(); public void insertMember_AttachFile(Member_AttachFile member_AttachFile); public Member_AttachFile detailMember_AttachFile(Member_AttachFile member_AttachFile); public void deleteMember_AttachFile(Member_AttachFile member_AttachFile); } | cs |
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 32 33 34 35 | <?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.lat.dao.Member_AttachFileMapper"> <resultMap type="Member_AttachFile" id="member_AttachFileMap"> <result property="id" column="ID"/> <result property="file_idx" column="FILE_IDX"/> <result property="origine" column="ORIGINE"/> <result property="attach" column="ATTACH"/> <result property="file_size" column="FILE_SIZE"/> <result property="path" column="PATH"/> <result property="file_type" column="FILE_TYPE"/> <result property="reg_date" column="REG_DATE"/> </resultMap> <select id="listMember_AttachFile" resultMap="member_AttachFileMap"> select * from member_attachfile </select> <insert id="insertMember_AttachFile" parameterType="com.lat.beans.Member_AttachFile"> insert into member_attachfile(id, file_idx, origine, attach, file_size, path, file_type, reg_date) values(#{id}, #{file_idx}, #{origine}, #{attach}, #{file_size}, #{path}, #{file_type}, sysdate) </insert> <select id="detailMember_AttachFile" parameterType="com.lat.beans.Member_AttachFile" resultType="com.lat.beans.Exam_AttachFile"> select * from member_attachfile where id=${id} </select> <delete id="deleteMember_AttachFile" parameterType="com.lat.beans.Member_AttachFile"> delete from member_attachfile where id=${id} </delete> </mapper> | cs |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import="com.lat.beans.Member_AttachFile" %> <%@ page import="java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>detailMemberAttachFile</title> </head> <body> Member_AttachFile상세보기 <% Member_AttachFile member_AttachFile=(Member_AttachFile)request.getAttribute("member_AttachFile"); if(member_AttachFile==null) member_AttachFile=new Member_AttachFile(); %> <table border="1"> <tr> <th>id</th> <th>file_idx</th> <th>origine</th> <th>attach</th> <th>file_size</th> <th>path</th> <th>file_type</th> <th>reg_date</th> </tr> <tr> <td><%=member_AttachFile.getId()%></td> <td><%=member_AttachFile.getFile_idx()%></td> <td><%=member_AttachFile.getOrigine()%></td> <td><%=member_AttachFile.getAttach()%></td> <td><%=member_AttachFile.getFile_size()%></td> <td><%=member_AttachFile.getPath()%></td> <td><%=member_AttachFile.getFile_type()%></td> <td><%=member_AttachFile.getReg_date()%></td> </tr> <tr> <td colspan="8"> <form method="post" action="delete"> <input type="hidden" name="id" value="<%=member_AttachFile.getId() %>"/> <input type="submit" value="삭제"/> </form> </td> </tr> </table> </body> </html> | cs |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import="com.lat.beans.Member_AttachFile" %> <%@ page import="java.util.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>insertMember_AttachFile</title> </head> <body> <% Member_AttachFile member_AttachFile=(Member_AttachFile)request.getAttribute("member_AttachFile"); if(member_AttachFile==null) member_AttachFile=new Member_AttachFile(); %> <form method="post" enctype="multipart/form-data" <% if(member_AttachFile.getId()==null){ %> action="insert" <% }else{ %> action="update" <% } %> > <table border="1"> <tr> <td>Id</td> <td> <% if(member_AttachFile.getId()==null){ %> <input type="text" name="id" value="<%=member_AttachFile.getId() %>"/> <% }else{ %> <input type="hidden" name="id" value="<%=member_AttachFile.getId() %>"/> <%=member_AttachFile.getId() %> <% } %> </td> </tr> <tr> <td>file_idx</td> <td><input type="text" name="file_idx" value="<%=member_AttachFile.getFile_idx()==0?"":member_AttachFile.getFile_idx() %>"/></td> </tr> <tr> <td>파일</td> <td><input type="file" name="f"></td> </tr> <tr> <td> <%if(member_AttachFile.getId()==null){ %> <input type="submit" value="등록"/> <%}else{ %> <input type="submit" value="수정"/> <%} %> <input type="reset" value="취소"/> </td> <td> <a href="listMember_AttachFile"> <input type="button" value="뒤로가기"/> </a> </td> </tr> </table> </form> </body> </html> | cs |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>listMember_AttachFile</title> </head> <body> <table border="1"> <tr> <th>id</th> <th>file_idx</th> <th>origine</th> <th>attach</th> <th>file_size</th> <th>path</th> <th>file_type</th> <th>reg_date</th> </tr> <c:forEach var="member_AttachFile" items="${list}"> <tr> <td> <a href="detailMember_AttachFile?id=${member_AttachFile.id}"> ${member_AttachFile.id} </a> </td> <td>${member_AttachFile.file_idx}</td> <td>${member_AttachFile.origine}</td> <td>${member_AttachFile.attach}</td> <td>${member_AttachFile.file_size}</td> <td>${member_AttachFile.path}</td> <td>${member_AttachFile.file_type}</td> <td>${member_AttachFile.reg_date}</td> </tr> </c:forEach> <tr> <td colspan="8"> <a href="insertMember_AttachFile"> <input type="button" value="insert"/> </a> </td> </tr> </table> </body> </html> | cs |
'Legend 개발자 > Spring' 카테고리의 다른 글
CRUD-example(Projectr_AttachFile) (0) | 2017.11.03 |
---|---|
CRUD-example(Exam_AttachFile) (0) | 2017.11.03 |
CRUD-example(investment) (0) | 2017.11.02 |
CRUD-example(reward) (0) | 2017.11.02 |
CRUD (0) | 2017.11.02 |