달력

12025  이전 다음

  • 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
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 Project_AttachFile {
    private long project_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 getProject_num() {
        return project_num;
    }
    public void setProject_num(long project_num) {
        this.project_num = project_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.Project_AttachFile;
import com.lat.dao.Project_AttachFileDAOService;
 
@Controller
public class Project_AttachFileController {
    @Autowired
    private Project_AttachFileDAOService project_AttachFileDAOService;
    
    @RequestMapping(value="/project_AttachFile/listProject_AttachFile")
    public ModelAndView list(HttpServletRequest request){
        List<Project_AttachFile> list=project_AttachFileDAOService.listProject_AttachFile();
        return new ModelAndView("project_AttachFile/listProject_AttachFile","list",list);
    }
    
    @RequestMapping(value="/project_AttachFile/insertProject_AttachFile")
    public ModelAndView insertReward(HttpServletRequest request){
        return new ModelAndView("project_AttachFile/insertProject_AttachFile");
    }
    
    @RequestMapping(value="/project_AttachFile/insert", method=RequestMethod.POST)
    public String listProject_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 project_num=request.getParameter("project_num");
        String file_idx=request.getParameter("file_idx");
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");
        Date date = new Date();
        String attach=format.format(date).toString();
        Project_AttachFile project_AttachFile=new Project_AttachFile();
        project_AttachFile.setProject_num(Long.parseLong(project_num));
        project_AttachFile.setFile_idx(Long.parseLong(file_idx));
        project_AttachFile.setOrigine((String)map.get("fileName"));
        project_AttachFile.setAttach(attach);
        project_AttachFile.setFile_size((Long)map.get("filesize"));
        project_AttachFile.setPath((String)map.get("uploadPath"));
        project_AttachFile.setFile_type((String)map.get("filetype"));
        project_AttachFileDAOService.insertProject_AttachFile(project_AttachFile);
        return "redirect:listProject_AttachFile";
    }
    
    @RequestMapping(value="/project_AttachFile/detailProject_AttachFile", method=RequestMethod.GET)
    public ModelAndView detailProject_AttachFile(HttpServletRequest request){
        String project_num=request.getParameter("project_num");
        Project_AttachFile project_AttachFile=new Project_AttachFile();
        project_AttachFile.setProject_num(Long.parseLong(project_num));
        ModelAndView result = new ModelAndView();
        Project_AttachFile project_AttachFileRlt=project_AttachFileDAOService.detailProject_AttachFile(project_AttachFile);
        result.addObject("project_AttachFile", project_AttachFileRlt);
        result.setViewName("project_AttachFile/detailProject_AttachFile");
        return result;
    }
    
    @RequestMapping(value="/project_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:/uploadProject_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="/project_AttachFile/delete", method=RequestMethod.POST)
    public String deleteProject_AttachFile(HttpServletRequest request){
        String project_num=request.getParameter("num");
        Project_AttachFile project_AttachFile=new Project_AttachFile();
        project_AttachFile.setProject_num(Long.parseLong(project_num));
        project_AttachFileDAOService.deleteProject_AttachFile(project_AttachFile);
        return "redirect:listProject_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.Project_AttachFile;
 
public interface Project_AttachFileDAO {
    public List<Project_AttachFile> listProject_AttachFile();
 
    public void insertProject_AttachFile(Project_AttachFile project_AttachFile);
 
    public Project_AttachFile detailProject_AttachFile(Project_AttachFile project_AttachFile);
 
    public void deleteProject_AttachFile(Project_AttachFile project_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.Project_AttachFile;
 
@Repository
public class Project_AttachFileDAOService implements Project_AttachFileDAO {
    @Autowired
    private SqlSession sqlSession;
 
    @Override
    public void insertProject_AttachFile(Project_AttachFile project_AttachFile) {
        // TODO Auto-generated method stub
        Project_AttachFileMapper project_AttachFileMapper = sqlSession.getMapper(Project_AttachFileMapper.class);
        project_AttachFileMapper.insertProject_AttachFile(project_AttachFile);
    }
 
    @Override
    public List<Project_AttachFile> listProject_AttachFile() {
        // TODO Auto-generated method stub
        Project_AttachFileMapper project_AttachFileMapper = sqlSession.getMapper(Project_AttachFileMapper.class);
        return project_AttachFileMapper.listProject_AttachFile();
    }
 
    @Override
    public Project_AttachFile detailProject_AttachFile(Project_AttachFile project_AttachFile) {
        // TODO Auto-generated method stub
        Project_AttachFileMapper project_AttachFileMapper = sqlSession.getMapper(Project_AttachFileMapper.class);
        return project_AttachFileMapper.detailProject_AttachFile(project_AttachFile);
    }
 
    @Override
    public void deleteProject_AttachFile(Project_AttachFile project_AttachFile) {
        // TODO Auto-generated method stub
        Project_AttachFileMapper project_AttachFileMapper = sqlSession.getMapper(Project_AttachFileMapper.class);
        project_AttachFileMapper.deleteProject_AttachFile(project_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.Project_AttachFile;
 
public interface Project_AttachFileMapper {
    public List<Project_AttachFile> listProject_AttachFile();
 
    public void insertProject_AttachFile(Project_AttachFile project_AttachFile);
 
    public Project_AttachFile detailProject_AttachFile(Project_AttachFile project_AttachFile);
 
    public void deleteProject_AttachFile(Project_AttachFile project_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.Project_AttachFileMapper">
    <resultMap type="Project_AttachFile" id="project_AttachFileMap">
        <result property="project_num" column="PROJECT_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="listProject_AttachFile" resultMap="project_AttachFileMap">
        select * from project_attachfile
    </select>
    
    <insert id="insertProject_AttachFile" parameterType="com.lat.beans.Project_AttachFile">
        insert into project_attachfile(project_num, file_idx, origine, attach, file_size, path, file_type, reg_date)
        values(#{project_num}, #{file_idx}, #{origine}, #{attach}, #{file_size}, #{path}, #{file_type}, sysdate)
    </insert>
    
    <select id="detailProject_AttachFile" parameterType="com.lat.beans.Project_AttachFile" resultType="com.lat.beans.Project_AttachFile">
        select * from project_attachfile
         where project_num=${project_num}
    </select>
    
    <delete id="deleteProject_AttachFile" parameterType="com.lat.beans.Project_AttachFile">
        delete from project_attachfile
         where project_num=${project_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.Project_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>detailProjectAttachFile</title>
</head>
<body>
Project_AttachFile상세보기
<%
    Project_AttachFile project_AttachFile=(Project_AttachFile)request.getAttribute("project_AttachFile");
    if(project_AttachFile==null) project_AttachFile=new Project_AttachFile();
%>
<table border="1">
    <tr>
        <th>project_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><%=project_AttachFile.getProject_num()%></td>
        <td><%=project_AttachFile.getFile_idx()%></td>
        <td><%=project_AttachFile.getOrigine()%></td>
        <td><%=project_AttachFile.getAttach()%></td>
        <td><%=project_AttachFile.getFile_size()%></td>
        <td><%=project_AttachFile.getPath()%></td>
        <td><%=project_AttachFile.getFile_type()%></td>
        <td><%=project_AttachFile.getReg_date()%></td>
    </tr>
    <tr>
        <td colspan="8">
            <form method="post" action="delete">
                <input type="hidden" name="project_num" value="<%=project_AttachFile.getProject_num() %>"/>
                <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.Project_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>insertProject_AttachFile</title>
</head>
<body>
<%
    Project_AttachFile project_AttachFile=(Project_AttachFile)request.getAttribute("project_AttachFile");
    if(project_AttachFile==null) project_AttachFile=new Project_AttachFile();
%>
<form method="post" enctype="multipart/form-data"
<if(project_AttachFile.getProject_num()==0){ %>
action="insert"
<% }else{ %>
action="update"
<% } %>
>
    <table border="1">
        <tr>
            <td>Project_num</td>
            <td>
            <if(project_AttachFile.getProject_num()==0){ %>
            <input type="text" name="project_num" value="<%=project_AttachFile.getProject_num() %>"/>
            <% }else{ %>
            <input type="hidden" name="project_num" value="<%=project_AttachFile.getProject_num() %>"/>
                <%=project_AttachFile.getProject_num() %>
            <% } %>
            </td>
        </tr>
        <tr>
            <td>file_idx</td>
            <td><input type="text" name="file_idx" value="<%=project_AttachFile.getFile_idx()==0?"":project_AttachFile.getFile_idx() %>"/></td>
        </tr>
        <tr>
            <td>파일</td>
            <td><input type="file" name="f"></td>
        </tr>
        <tr>
            <td>
            <%if(project_AttachFile.getProject_num()==0){ %>
                <input type="submit" value="등록"/>
            <%}else{ %>
                <input type="submit" value="수정"/>
            <%} %>
                <input type="reset" value="취소"/>
            </td>
            <td>
                <a href="listProject_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>listProject_AttachFile</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>project_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="project_AttachFile" items="${list}">
        <tr>
            <td>
                <a href="detailProject_AttachFile?project_num=${project_AttachFile.project_num}">
                    ${project_AttachFile.project_num}
                </a>
            </td>
            <td>${project_AttachFile.file_idx}</td>
            <td>${project_AttachFile.origine}</td>
            <td>${project_AttachFile.attach}</td>
            <td>${project_AttachFile.file_size}</td>
            <td>${project_AttachFile.path}</td>
            <td>${project_AttachFile.file_type}</td>
            <td>${project_AttachFile.reg_date}</td>
        </tr>
    </c:forEach>
        <tr>
            <td colspan="8">
                <a href="insertProject_AttachFile">
                    <input type="button" value="insert"/>
                </a>
            </td>
        </tr>
    </table>
</body>
</html>
 
cs






'Legend 개발자 > Spring' 카테고리의 다른 글

CRUD-example(Member_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
Posted by 전설의아이
|