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 Exam_AttachFile { private long num; 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 long getNum() { return num; } public void setNum(long num) { this.num = num; } 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.Exam_AttachFile; import com.lat.dao.Exam_AttachFileDAOService; @Controller public class Exam_AttachFileController { @Autowired private Exam_AttachFileDAOService exam_AttachFileDAOService; @RequestMapping(value="/exam_AttachFile/listExam_AttachFile") public ModelAndView list(HttpServletRequest request){ List<Exam_AttachFile> list=exam_AttachFileDAOService.listExam_AttachFile(); return new ModelAndView("exam_AttachFile/listExam_AttachFile","list",list); } @RequestMapping(value="/exam_AttachFile/insertExam_AttachFile") public ModelAndView insertReward(HttpServletRequest request){ return new ModelAndView("exam_AttachFile/insertExam_AttachFile"); } @RequestMapping(value="/exam_AttachFile/insert", method=RequestMethod.POST) public String listExam_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 num=request.getParameter("num"); String file_idx=request.getParameter("file_idx"); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss"); Date date = new Date(); String attach = format.format(date).toString(); Exam_AttachFile exam_AttachFile=new Exam_AttachFile(); exam_AttachFile.setNum(Long.parseLong(num)); exam_AttachFile.setFile_idx(Long.parseLong(file_idx)); exam_AttachFile.setOrigine((String)map.get("fileName")); exam_AttachFile.setAttach(attach); exam_AttachFile.setFile_size((Long)map.get("filesize")); exam_AttachFile.setPath((String)map.get("uploadPath")); exam_AttachFile.setFile_type((String)map.get("filetype")); exam_AttachFileDAOService.insertExam_AttachFile(exam_AttachFile); return "redirect:listExam_AttachFile"; } @RequestMapping(value="/exam_AttachFile/detailExam_AttachFile", method=RequestMethod.GET) public ModelAndView detailExam_AttachFile(HttpServletRequest request){ String num=request.getParameter("num"); Exam_AttachFile exam_AttachFile=new Exam_AttachFile(); exam_AttachFile.setNum(Long.parseLong(num)); ModelAndView result = new ModelAndView(); Exam_AttachFile exam_AttachFileRlt=exam_AttachFileDAOService.detailExam_AttachFile(exam_AttachFile); result.addObject("exam_AttachFile", exam_AttachFileRlt); result.setViewName("exam_AttachFile/detailExam_AttachFile"); return result; } @RequestMapping(value="/exam_AttachFile/multipartHttpServletRequest") 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:/uploadExam_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="/exam_AttachFile/delete", method=RequestMethod.POST) public String deleteExam_AttachFile(HttpServletRequest request){ String num=request.getParameter("num"); Exam_AttachFile exam_AttachFile=new Exam_AttachFile(); exam_AttachFile.setNum(Long.parseLong(num)); exam_AttachFileDAOService.deleteExam_AttachFile(exam_AttachFile); return "redirect:listExam_AttachFile"; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | package com.lat.dao; import java.util.List; import com.lat.beans.Exam_AttachFile; public interface Exam_AttachFileDAO { public List<Exam_AttachFile> listExam_AttachFile(); public void insertExam_AttachFile(Exam_AttachFile exam_AttachFile); public Exam_AttachFile detailExam_AttachFile(Exam_AttachFile exam_AttachFile); public void deleteExam_AttachFile(Exam_AttachFile exam_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 45 | 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.Exam_AttachFile; @Repository public class Exam_AttachFileDAOService implements Exam_AttachFileDAO { @Autowired private SqlSession sqlSession; @Override public void insertExam_AttachFile(Exam_AttachFile exam_AttachFile) { // TODO Auto-generated method stub Exam_AttachFileMapper exam_AttachFileMapper = sqlSession.getMapper(Exam_AttachFileMapper.class); exam_AttachFileMapper.insertExam_AttachFile(exam_AttachFile); } @Override public List<Exam_AttachFile> listExam_AttachFile() { // TODO Auto-generated method stub Exam_AttachFileMapper exam_AttachFileMapper = sqlSession.getMapper(Exam_AttachFileMapper.class); return exam_AttachFileMapper.listExam_AttachFile(); } @Override public Exam_AttachFile detailExam_AttachFile(Exam_AttachFile exam_AttachFile) { // TODO Auto-generated method stub Exam_AttachFileMapper exam_AttachFileMapper = sqlSession.getMapper(Exam_AttachFileMapper.class); return exam_AttachFileMapper.detailExam_AttachFile(exam_AttachFile); } @Override public void deleteExam_AttachFile(Exam_AttachFile exam_AttachFile) { // TODO Auto-generated method stub Exam_AttachFileMapper exam_AttachFileMapper = sqlSession.getMapper(Exam_AttachFileMapper.class); exam_AttachFileMapper.deleteExam_AttachFile(exam_AttachFile); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | package com.lat.dao; import java.util.List; import com.lat.beans.Exam_AttachFile; public interface Exam_AttachFileMapper { public List<Exam_AttachFile> listExam_AttachFile(); public void insertExam_AttachFile(Exam_AttachFile exam_AttachFile); public Exam_AttachFile detailExam_AttachFile(Exam_AttachFile exam_AttachFile); public void deleteExam_AttachFile(Exam_AttachFile exam_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.Exam_AttachFileMapper"> <resultMap type="Exam_AttachFile" id="exam_AttachFileMap"> <result property="num" column="NUM"/> <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="listExam_AttachFile" resultMap="exam_AttachFileMap"> select * from exam_attachfile </select> <insert id="insertExam_AttachFile" parameterType="com.lat.beans.Exam_AttachFile"> insert into exam_attachfile(num, file_idx, origine, attach, file_size, path, file_type, reg_date) values(#{num}, #{file_idx}, #{origine}, #{attach}, #{file_size}, #{path}, #{file_type}, sysdate) </insert> <select id="detailExam_AttachFile" parameterType="com.lat.beans.Exam_AttachFile" resultType="com.lat.beans.Exam_AttachFile"> select * from exam_attachfile where num=${num} </select> <delete id="deleteExam_AttachFile" parameterType="com.lat.beans.Exam_AttachFile"> delete from exam_attachfile where num=${num} </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.Exam_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>detailExamAttachFile</title> </head> <body> Exam_AttachFile상세보기 <% Exam_AttachFile exam_AttachFile=(Exam_AttachFile)request.getAttribute("exam_AttachFile"); if(exam_AttachFile==null) exam_AttachFile=new Exam_AttachFile(); %> <table border="1"> <tr> <th>num</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><%=exam_AttachFile.getNum()%></td> <td><%=exam_AttachFile.getFile_idx()%></td> <td><%=exam_AttachFile.getOrigine()%></td> <td><%=exam_AttachFile.getAttach()%></td> <td><%=exam_AttachFile.getFile_size()%></td> <td><%=exam_AttachFile.getPath()%></td> <td><%=exam_AttachFile.getFile_type()%></td> <td><%=exam_AttachFile.getReg_date()%></td> </tr> <tr> <td colspan="8"> <form method="post" action="delete"> <input type="hidden" name="num" value="<%=exam_AttachFile.getNum() %>"/> <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.Exam_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>insertExam_AttachFile</title> </head> <body> <% Exam_AttachFile exam_AttachFile=(Exam_AttachFile)request.getAttribute("exam_AttachFile"); if(exam_AttachFile==null) exam_AttachFile=new Exam_AttachFile(); %> <form method="post" enctype="multipart/form-data" <% if(exam_AttachFile.getNum()==0){ %> action="insert" <% }else{ %> action="update" <% } %> > <table border="1"> <tr> <td>Num</td> <td> <% if(exam_AttachFile.getNum()==0){ %> <input type="text" name="num" value="<%=exam_AttachFile.getNum() %>"/> <% }else{ %> <input type="hidden" name="num" value="<%=exam_AttachFile.getNum() %>"/> <%=exam_AttachFile.getNum() %> <% } %> </td> </tr> <tr> <td>file_idx</td> <td><input type="text" name="file_idx" value="<%=exam_AttachFile.getFile_idx()==0?"":exam_AttachFile.getFile_idx() %>"/></td> </tr> <tr> <td>파일</td> <td><input type="file" name="f"></td> </tr> <tr> <td> <%if(exam_AttachFile.getNum()==0){ %> <input type="submit" value="등록"/> <%}else{ %> <input type="submit" value="수정"/> <%} %> <input type="reset" value="취소"/> </td> <td> <a href="listExam_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>listExam_AttachFile</title> </head> <body> <table border="1"> <tr> <th>num</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="exam_AttachFile" items="${list}"> <tr> <td> <a href="detailExam_AttachFile?num=${exam_AttachFile.num}"> ${exam_AttachFile.num} </a> </td> <td>${exam_AttachFile.file_idx}</td> <td>${exam_AttachFile.origine}</td> <td>${exam_AttachFile.attach}</td> <td>${exam_AttachFile.file_size}</td> <td>${exam_AttachFile.path}</td> <td>${exam_AttachFile.file_type}</td> <td>${exam_AttachFile.reg_date}</td> </tr> </c:forEach> <tr> <td colspan="8"> <a href="insertExam_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(Member_AttachFile) (0) | 2017.11.03 |
CRUD-example(investment) (0) | 2017.11.02 |
CRUD-example(reward) (0) | 2017.11.02 |
CRUD (0) | 2017.11.02 |