달력

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

'Legend 개발자/Spring'에 해당되는 글 6건

  1. 2017.11.03 CRUD-example(Projectr_AttachFile)
  2. 2017.11.03 CRUD-example(Member_AttachFile)
  3. 2017.11.03 CRUD-example(Exam_AttachFile)
  4. 2017.11.02 CRUD-example(investment)
  5. 2017.11.02 CRUD-example(reward)
  6. 2017.11.02 CRUD
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 전설의아이
|
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
Posted by 전설의아이
|
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
Posted by 전설의아이
|
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
package com.lat.beans;
 
public class Investment {
    private String id;
    private long project_num;
    private long reward_num;
    private long total;
    private String addr;
    private String card_num;
    private String card_exdate;
    private String card_pwd;
    private String card_birth;
    
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public long getProject_num() {
        return project_num;
    }
    public void setProject_num(long project_num) {
        this.project_num = project_num;
    }
    public long getReward_num() {
        return reward_num;
    }
    public void setReward_num(long reward_num) {
        this.reward_num = reward_num;
    }
    public long getTotal() {
        return total;
    }
    public void setTotal(long total) {
        this.total = total;
    }
    public String getAddr() {
        return addr;
    }
    public void setAddr(String addr) {
        this.addr = addr;
    }
    public String getCard_num() {
        return card_num;
    }
    public void setCard_num(String card_num) {
        this.card_num = card_num;
    }
    public String getCard_exdate() {
        return card_exdate;
    }
    public void setCard_exdate(String card_exdate) {
        this.card_exdate = card_exdate;
    }
    public String getCard_pwd() {
        return card_pwd;
    }
    public void setCard_pwd(String card_pwd) {
        this.card_pwd = card_pwd;
    }
    public String getCard_birth() {
        return card_birth;
    }
    public void setCard_birth(String card_birth) {
        this.card_birth = card_birth;
    }
    
}
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.lat.controller;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
 
import com.lat.beans.Investment;
import com.lat.dao.InvestmentDAOService;
 
@Controller
public class InvestmentController {
    @Autowired
    private InvestmentDAOService investmentDAOService;
    
    @RequestMapping(value="/investment/listInvestment")
    public ModelAndView list(HttpServletRequest request){
        List<Investment> list=investmentDAOService.listInvestment();
        return new ModelAndView("investment/listInvestment","list",list);
    }
    
    @RequestMapping(value="/investment/insertInvestment")
    public ModelAndView insertInvestment(HttpServletRequest request){
        return new ModelAndView("investment/insertInvestment");
    }
    
    @RequestMapping(value="/investment/insert", method=RequestMethod.POST)
    public String listInvestment(HttpServletRequest request){
        String id=request.getParameter("id");
        String project_numVal=request.getParameter("project_num");
        long project_num=0;
        if(project_numVal!=null) project_num=Long.parseLong(project_numVal);
        String reward_numVal=request.getParameter("reward_num");
        long reward_num=0;
        if(reward_numVal!=null) reward_num=Long.parseLong(reward_numVal);
        String totalVal=request.getParameter("total");
        long total=0;
        if(totalVal!=null) total=Long.parseLong(totalVal);
        String addr=request.getParameter("addr");
        String card_num=request.getParameter("card_num");
        String card_exdate=request.getParameter("card_exdate");
        String card_pwd=request.getParameter("card_pwd");
        String card_birth=request.getParameter("card_birth");
        Investment investment=new Investment();
        investment.setId(id);
        investment.setProject_num(project_num);
        investment.setReward_num(reward_num);
        investment.setTotal(total);
        investment.setAddr(addr);
        investment.setCard_num(card_num);
        investment.setCard_exdate(card_exdate);
        investment.setCard_pwd(card_pwd);
        investment.setCard_birth(card_birth);
        investmentDAOService.insertInvestment(investment);
        return "redirect:listInvestment";
    }
    
    @RequestMapping(value="/investment/detailInvestment", method=RequestMethod.GET)
    public ModelAndView detailInvestment(HttpServletRequest request){
        String id=request.getParameter("id");
        String project_numVal=request.getParameter("project_num");
        long project_num=0;
        if(project_numVal!=null) project_num=Long.parseLong(project_numVal);
        String reward_numVal=request.getParameter("reward_num");
        long reward_num=0;
        if(reward_numVal!=null) reward_num=Long.parseLong(reward_numVal);
        Investment investment = new Investment();
        investment.setId(id);
        investment.setProject_num(project_num);
        investment.setReward_num(reward_num);
        investment=investmentDAOService.detailInvestment(investment);
        return new ModelAndView("investment/detailInvestment","investment",investment);
    }
        
    @RequestMapping(value="/investment/update", method=RequestMethod.POST)
    public String update(HttpServletRequest request){
        String id=request.getParameter("id");
        String project_numVal=request.getParameter("project_num");
        long project_num=0;
        if(project_numVal!=null) project_num=Long.parseLong(project_numVal);
        String reward_numVal=request.getParameter("reward_num");
        long reward_num=0;
        if(reward_numVal!=null) reward_num=Long.parseLong(reward_numVal);
        String totalVal=request.getParameter("total");
        long total=0;
        if(totalVal!=null) total=Long.parseLong(totalVal);
        String addr=request.getParameter("addr");
        String card_num=request.getParameter("card_num");
        String card_exdate=request.getParameter("card_exdate");
        String card_pwd=request.getParameter("card_pwd");
        String card_birth=request.getParameter("card_birth");
        Investment investment=new Investment();
        investment.setId(id);
        investment.setProject_num(project_num);
        investment.setReward_num(reward_num);
        investment.setTotal(total);
        investment.setAddr(addr);
        investment.setCard_num(card_num);
        investment.setCard_exdate(card_exdate);
        investment.setCard_pwd(card_pwd);
        investment.setCard_birth(card_birth);
        investmentDAOService.updateInvestment(investment);
        return "redirect:listInvestment";
    }
 
    @RequestMapping(value="/investment/updateInvestment")
    public ModelAndView updateInvestment(HttpServletRequest request){
        String id=request.getParameter("id");
        String project_numVal=request.getParameter("project_num");
        long project_num=0;
        if(project_numVal!=null) project_num=Long.parseLong(project_numVal);
        String reward_numVal=request.getParameter("reward_num");
        long reward_num=0;
        if(reward_numVal!=null) reward_num=Long.parseLong(reward_numVal);
        Investment investment = new Investment();
        investment.setId(id);
        investment.setProject_num(project_num);
        investment.setReward_num(reward_num);
        Investment investmentRlt=investmentDAOService.detailInvestment(investment);
        ModelAndView view=new ModelAndView("investment/insertInvestment");
        view.addObject("investment",investmentRlt);
        return view;
    }
    
    @RequestMapping(value="/investment/delete", method=RequestMethod.POST)
    public String delete(HttpServletRequest request){
        String id=request.getParameter("id");
        String project_numVal=request.getParameter("project_num");
        long project_num=0;
        if(project_numVal!=null) project_num=Long.parseLong(project_numVal);
        String reward_numVal=request.getParameter("reward_num");
        long reward_num=0;
        if(reward_numVal!=null) reward_num=Long.parseLong(reward_numVal);
        Investment investment=new Investment();
        investment.setId(id);
        investment.setProject_num(project_num);
        investment.setReward_num(reward_num);
        investmentDAOService.deleteInvestment(investment);
        return "redirect:listInvestment";
    }
}
 
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.Investment;
 
public interface InvestmentDAO {
    public List<Investment> listInvestment();
    public void insertInvestment(Investment investment);
    public Investment detailInvestment(Investment investment);
    public void updateInvestment(Investment investment);
    public void deleteInvestment(Investment investment);    
}
 
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
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.Investment;
 
@Repository
public class InvestmentDAOService implements InvestmentDAO {
 
        @Autowired
        private SqlSession sqlSession;
 
        @Override
        public void insertInvestment(Investment investment) {
            // TODO Auto-generated method stub
            InvestmentMapper investmentMapper=sqlSession.getMapper(InvestmentMapper.class);
            investmentMapper.insertInvestment(investment);
        }
        @Override
        public List<Investment> listInvestment() {
            // TODO Auto-generated method stub
            InvestmentMapper investmentMapper=sqlSession.getMapper(InvestmentMapper.class);
            return investmentMapper.listInvestment();
        }
        @Override
        public Investment detailInvestment(Investment investment) {
            // TODO Auto-generated method stub
            InvestmentMapper investmentMapper=sqlSession.getMapper(InvestmentMapper.class);
            return investmentMapper.detailInvestment(investment);
        }
 
        @Override
        public void updateInvestment(Investment investment) {
            // TODO Auto-generated method stub
            InvestmentMapper investmentMapper=sqlSession.getMapper(InvestmentMapper.class);
            investmentMapper.updateInvestment(investment);
            
        }
 
        @Override
        public void deleteInvestment(Investment investment) {
            // TODO Auto-generated method stub
            InvestmentMapper investmentMapper=sqlSession.getMapper(InvestmentMapper.class);
            investmentMapper.deleteInvestment(investment);
            
        }
        
}
 
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.Investment;
 
public interface InvestmentMapper {
    public List<Investment> listInvestment();
    public void insertInvestment(Investment investment);
    public Investment detailInvestment(Investment investment);
    public void updateInvestment(Investment investment);
    public void deleteInvestment(Investment investment);
}
 
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
<?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.InvestmentMapper">
    <resultMap type="Investment" id="investmentMap">
        <result property="id" column="ID"/>
        <result property="project_num" column="PROJECT_NUM"/>
        <result property="reward_num" column="REWARD_NUM"/>
        <result property="total" column="TOTAL"/>
        <result property="addr" column="ADDR"/>
        <result property="card_num" column="CARD_NUM"/>
        <result property="card_exdate" column="CARD_EXDATE"/>
        <result property="card_pwd" column="CARD_PWD"/>
        <result property="card_birth" column="CARD_BIRTH"/>
    </resultMap>
    
    <select id="listInvestment" resultMap="investmentMap">
        select * from investment
    </select>
    
    <insert id="insertInvestment" parameterType="com.lat.beans.Investment">
        insert into investment(id, project_num, reward_num, total, addr, card_num, card_exdate, card_pwd, card_birth)
        values(#{id}, #{project_num}, #{reward_num}, #{total}, #{addr}, #{card_num}, #{card_exdate}, #{card_pwd}, #{card_birth})
    </insert>
    
    <select id="detailInvestment" parameterType="com.lat.beans.Investment" resultType="com.lat.beans.Investment">
        select * from investment
         where id=#{id}
           and project_num=#{project_num}
           and reward_num=#{reward_num}
    </select>
    
    <update id="updateInvestment" parameterType="com.lat.beans.Investment">
        update investment set
            total=#{total}
           ,addr=#{addr}
           ,card_num=#{card_num}
           ,card_exdate=#{card_exdate}
           ,card_pwd=#{card_pwd}
           ,card_birth=#{card_birth}
        where id=#{id}
          and project_num=#{project_num}
          and reward_num=#{reward_num}
    </update>
    
    <delete id="deleteInvestment" parameterType="com.lat.beans.Investment">
        delete from investment
         where id=#{id}
           and project_num=#{project_num}
           and reward_num=#{reward_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
49
50
51
52
53
54
55
56
57
58
59
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.lat.beans.Investment" %>
<%@ 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>detailInvestment</title>
</head>
<body>
Investment상세보기
<%
    Investment investment=(Investment)request.getAttribute("investment");
    if(investment==null) investment=new Investment();
%>
<table border="1">
    <tr>
        <th>id</th>
        <th>project_num</th>
        <th>reward_num</th>
        <th>total</th>
        <th>addr</th>
        <th>card_num</th>
        <th>card_exdate</th>
        <th>card_pwd</th>
        <th>card_birth</th>
    </tr>
    <tr>
        <td><%=investment.getId() %></td>
        <td><%=investment.getProject_num() %></td>
        <td><%=investment.getReward_num() %></td>
        <td><%=investment.getTotal() %></td>
        <td><%=investment.getAddr() %></td>
        <td><%=investment.getCard_num() %></td>
        <td><%=investment.getCard_exdate() %></td>
        <td><%=investment.getCard_pwd() %></td>
        <td><%=investment.getCard_birth() %></td>
    </tr>
    <tr>
        <td colspan="9">
            <form method="post" action="updateInvestment">
                <input type="hidden" name="id" value="<%=investment.getId() %>"/>
                <input type="hidden" name="project_num" value="<%=investment.getProject_num() %>"/>
                <input type="hidden" name="reward_num" value="<%=investment.getReward_num() %>"/>
                <input type="submit" value="수정"/>
            </form>    
            <form method="post" action="delete">
                <input type="hidden" name="id" value="<%=investment.getId() %>"/>
                <input type="hidden" name="project_num" value="<%=investment.getProject_num() %>"/>
                <input type="hidden" name="reward_num" value="<%=investment.getReward_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
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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.lat.beans.Investment" %>
<%@ 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>insertInvestment</title>
</head>
<body>
<%
    Investment investment=(Investment)request.getAttribute("investment");
    if(investment==null) investment=new Investment();
%>
<form method="post"
<% if(investment.getId()==null){ %>
action="insert"
<% }else{ %>
action="update"
<% } %>
>
    <table border="1">
        <tr>
            <td>Id</td>
            <td colspan="2">
            <% if(investment.getId()==null){ %>
            <input type="text" name="id" value="<%=investment.getId() %>"/>
            <% }else{ %>
            <input type="hidden" name="id" value="<%=investment.getId() %>"/>
                <%=investment.getId() %>
            <% } %>
            </td>
        </tr>
        <tr>
            <td>Project_num</td>
            <td colspan="2">
            <% if(investment.getProject_num()==0){ %>
            <input type="text" name="project_num" value="<%=investment.getProject_num() %>"/>
            <% }else{ %>
            <input type="hidden" name="project_num" value="<%=investment.getProject_num() %>"/>
                <%=investment.getProject_num() %>
            <% } %>
            </td>
        </tr>
        <tr>
            <td>Reward_num</td>
            <td colspan="2">
            <% if(investment.getReward_num()==0){ %>
            <input type="text" name="reward_num" value="<%=investment.getReward_num() %>"/>
            <% }else{ %>
            <input type="hidden" name="reward_num" value="<%=investment.getReward_num() %>"/>
                <%=investment.getReward_num() %>
            <% } %>
            </td>
        </tr>
        <tr>
            <td>total</td>
            <td colspan="2"><input type="text" name="total" value="<%=investment.getTotal()==0?"":investment.getTotal() %>"/></td>
        </tr>
        <tr>
            <td>addr</td>
            <td colspan="2"><input type="text" name="addr" value="<%=investment.getAddr()==null?"":investment.getAddr() %>"/></td>
        </tr>
        <tr>
            <td>card_num</td>
            <td colspan="2"><input type="text" name="card_num" value="<%=investment.getCard_num()==null?"":investment.getCard_num() %>"/></td>
        </tr>
        <tr>
            <td>card_exdate</td>
            <td colspan="2"><input type="text" name="card_exdate" value="<%=investment.getCard_exdate()==null?"":investment.getCard_exdate() %>"/></td>
        </tr>
        <tr>
            <td>card_pwd</td>
            <td colspan="2"><input type="text" name="card_pwd" value="<%=investment.getCard_pwd()==null?"":investment.getCard_pwd() %>"/></td>
        </tr>
        <tr>
            <td>card_birth</td>
            <td colspan="2"><input type="text" name="card_birth" value="<%=investment.getCard_birth()==null?"":investment.getCard_birth() %>"/></td>
        </tr>
        <tr>
            <td>
            <%if(investment.getId()==null){ %>
                <input type="submit" value="등록"/>
            <%}else{ %>
                <input type="submit" value="수정"/>
            <%} %>
                <input type="reset" value="취소"/>
            </td>
            <td>
                <a href="listInvestment">
                    <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
49
<%@ 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>listInvestment</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>id</th>
            <th>project_num</th>
            <th>reward_num</th>
            <th>total</th>
            <th>addr</th>
            <th>card_num</th>
            <th>card_exdate</th>
            <th>card_pwd</th>
            <th>card_birth</th>
        </tr>
    <c:forEach var="investment" items="${list}">
        <tr>
            <td>
                <a href="detailInvestment?id=${investment.id}&project_num=${investment.project_num}&reward_num=${investment.reward_num}">
                    ${investment.id}
                </a>
            </td>
            <td>${investment.project_num}</td>
            <td>${investment.reward_num}</td>
            <td>${investment.total}</td>
            <td>${investment.addr}</td>
            <td>${investment.card_num}</td>
            <td>${investment.card_exdate}</td>
            <td>${investment.card_pwd}</td>
            <td>${investment.card_birth}</td>
        </tr>
    </c:forEach>
        <tr>
            <td colspan="9">
                <a href="insertInvestment">
                    <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(Exam_AttachFile)  (0) 2017.11.03
CRUD-example(reward)  (0) 2017.11.02
CRUD  (0) 2017.11.02
Posted by 전설의아이
|
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
package com.lat.beans;
 
public class Reward {
    private long project_num;
    private long reward_num;
    private String name;
    private long price;
    private String item;
    private long min;
    
    public long getProject_num() {
        return project_num;
    }
    public void setProject_num(long project_num) {
        this.project_num = project_num;
    }
    public long getReward_num() {
        return reward_num;
    }
    public void setReward_num(long reward_num) {
        this.reward_num = reward_num;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public long getPrice() {
        return price;
    }
    public void setPrice(long price) {
        this.price = price;
    }
    public String getItem() {
        return item;
    }
    public void setItem(String item) {
        this.item = item;
    }
    public long getMin() {
        return min;
    }
    public void setMin(long min) {
        this.min = min;
    }
    
}
 
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.lat.controller;
 
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
 
import com.lat.beans.Reward;
import com.lat.dao.RewardDAOService;
 
@Controller
public class RewardController {
    @Autowired
    private RewardDAOService rewardDAOService;
    
    @RequestMapping(value="/reward/listReward")
    public ModelAndView list(HttpServletRequest request){
        List<Reward> list=rewardDAOService.listReward();
        return new ModelAndView("reward/listReward","list",list);
    }
    
    @RequestMapping(value="/reward/insertReward")
    public ModelAndView insertReward(HttpServletRequest request){
        return new ModelAndView("reward/insertReward");
    }
    
    @RequestMapping(value="/reward/insert", method=RequestMethod.POST)
    public String listReward(HttpServletRequest request){
        String project_num=request.getParameter("project_num");//숫자
        String reward_num=request.getParameter("reward_num");//숫자
        String name=request.getParameter("name");
        String price=request.getParameter("price");//숫자
        String item=request.getParameter("item");
        String min=request.getParameter("min");//숫자
        Reward reward=new Reward();
        reward.setProject_num(Long.parseLong(project_num));
        reward.setReward_num(Long.parseLong(reward_num));
        reward.setName(name);
        reward.setPrice(Long.parseLong(price));
        reward.setItem(item);
        reward.setMin(Long.parseLong(min));
        rewardDAOService.insertReward(reward);
        return "redirect:listReward";
    }
    
    @RequestMapping(value="/reward/detailReward", method=RequestMethod.GET)
    public ModelAndView detailReward(HttpServletRequest request){
        String project_num=request.getParameter("project_num");
        String reward_num=request.getParameter("reward_num");
        Reward reward=new Reward();
        reward.setProject_num(Long.parseLong(project_num));
        reward.setReward_num(Long.parseLong(reward_num));
        ModelAndView result= new ModelAndView();
        Reward rewardRlt=rewardDAOService.detailReward(reward);
        result.addObject("reward",rewardRlt);
        result.setViewName("reward/detailReward");
        return result;
    }
    
    @RequestMapping(value="/reward/update")
    public String update(HttpServletRequest request){
    String project_numVal=request.getParameter("project_num");
    long project_num=0;
    if(project_numVal!=null) project_num=Long.parseLong(project_numVal);
    String reward_numVal=request.getParameter("reward_num");//숫자
    long reward_num=0;
    if(reward_numVal!=null) reward_num=Long.parseLong(reward_numVal);
    String name=request.getParameter("name");
    String priceVal=request.getParameter("price");//숫자
    long price=0;
    if(priceVal!=null) price=Long.parseLong(priceVal);
    String item=request.getParameter("item");
    String minVal=request.getParameter("min");//숫자
    long min=0;
    if(minVal!=null) min=Long.parseLong(minVal);
    Reward reward=new Reward();
    reward.setProject_num(project_num);
    reward.setReward_num(reward_num);
    reward.setName(name);
    reward.setPrice(price);
    reward.setItem(item);
    reward.setMin(min);
    rewardDAOService.updateReward(reward);
    return "redirect:listReward";
    }
    
    @RequestMapping(value="/reward/updateReward", method=RequestMethod.POST)
    public ModelAndView updateReward(HttpServletRequest request){
        String project_num=request.getParameter("project_num");
        String reward_num=request.getParameter("reward_num");
        Reward reward=new Reward();
        reward.setProject_num(Long.parseLong(project_num));
        reward.setReward_num(Long.parseLong(reward_num));
        Reward rewardRlt=rewardDAOService.detailReward(reward);
        ModelAndView view=new ModelAndView("reward/insertReward");
        view.addObject("reward",rewardRlt);
        return view;
    }
    
    @RequestMapping(value="/reward/delete", method=RequestMethod.POST)
    public String deleteReward(HttpServletRequest request){
        String project_num=request.getParameter("project_num");
        String reward_num=request.getParameter("reward_num");
        Reward reward=new Reward();
        reward.setProject_num(Long.parseLong(project_num));
        reward.setReward_num(Long.parseLong(reward_num));
        rewardDAOService.deleteReward(reward);
        return "redirect:listReward";
    }
    
}
 
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.Reward;
 
public interface RewardDAO {
    public List<Reward> listReward();
    public void insertReward(Reward reward);
    public Reward detailReward(Reward reward);
    public void updateReward(Reward reward);
    public void deleteReward(Reward reward);
}
 
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
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.Reward;
 
@Repository
public class RewardDAOService implements RewardDAO{
 
    @Autowired
    private SqlSession sqlSession;
 
 
    @Override
    public void insertReward(Reward reward) {
        // TODO Auto-generated method stub
        RewardMapper rewardMapper=sqlSession.getMapper(RewardMapper.class);
        rewardMapper.insertReward(reward);
    }
 
    @Override
    public List<Reward> listReward() {
        // TODO Auto-generated method stub
        RewardMapper rewardMapper=sqlSession.getMapper(RewardMapper.class);
        return rewardMapper.listReward();
    }
    @Override
    public Reward detailReward(Reward reward) {
        // TODO Auto-generated method stub
        RewardMapper rewardMapper=sqlSession.getMapper(RewardMapper.class);
        return rewardMapper.detailReward(reward);
    }
 
    @Override
    public void updateReward(Reward reward) {
        // TODO Auto-generated method stub
        RewardMapper rewardMapper=sqlSession.getMapper(RewardMapper.class);
        rewardMapper.updateReward(reward);
    }
 
    @Override
    public void deleteReward(Reward reward) {
        // TODO Auto-generated method stub
        RewardMapper rewardMapper=sqlSession.getMapper(RewardMapper.class);
        rewardMapper.deleteReward(reward);
    }
 
}
 
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.Reward;
 
public interface RewardMapper {
 
    public List<Reward> listReward();
    public void insertReward(Reward reward);
    public Reward detailReward(Reward reward);
    public void updateReward(Reward reward);
    public void deleteReward(Reward reward);
 
}
 
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
<?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.RewardMapper">
    <resultMap type="Reward" id="rewardMap">
        <result property="project_num" column="PROJECT_NUM"/>
        <result property="reward_num" column="REWARD_NUM"/>
        <result property="name" column="NAME"/>
        <result property="price" column="PRICE"/>
        <result property="item" column="ITEM"/>
        <result property="min" column="MIN"/>
    </resultMap>
    
    <select id="listReward" resultMap="rewardMap">
        select * from reward
    </select>
    
    <insert id="insertReward" parameterType="com.lat.beans.Reward">
        insert into reward(project_num, reward_num, name, price, item, min)
        values(#{project_num}, #{reward_num}, #{name}, #{price}, #{item}, #{min})
    </insert>
    
    <select id="detailReward" parameterType="com.lat.beans.Reward" resultType="com.lat.beans.Reward">
        select * from reward
        where project_num=#{project_num} and reward_num=#{reward_num}
    </select>
    
    <update id="updateReward" parameterType="com.lat.beans.Reward">
        update reward set 
         name=#{name}
        ,price=#{price}
        ,item=#{item}        
        ,min=#{min}
        where project_num=#{project_num}
          and reward_num=#{reward_num}
    </update>
    
    <delete id="deleteReward" parameterType="com.lat.beans.Reward">
        delete from reward
        where project_num=#{project_num}
          and reward_num=#{reward_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
49
50
51
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.lat.beans.Reward"%>
<%@ 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>detailReward</title>
</head>
<body>
Reward상세보기
<%
    Reward reward=(Reward)request.getAttribute("reward");
    if(reward==null) reward=new Reward();
%>
<table border="1">
    <tr>
        <th>project_num</th>
        <th>reward_num</th>
        <th>name</th>
        <th>price</th>
        <th>item</th>
        <th>min</th>
    </tr>
    <tr>
        <td><%=reward.getProject_num()%></td>
        <td><%=reward.getReward_num()%></td>
        <td><%=reward.getName()%></td>
        <td><%=reward.getPrice()%></td>
        <td><%=reward.getItem()%></td>
        <td><%=reward.getMin()%></td>
    </tr>
    <tr>
        <td colspan="6">
            <form method="post" action="updateReward">
                <input type="hidden" name="project_num" value="<%=reward.getProject_num() %>"/>
                <input type="hidden" name="reward_num" value="<%=reward.getReward_num() %>"/>
                <input type="submit" value="수정"/>
            </form>    
            <form method="post" action="delete">
                <input type="hidden" name="project_num" value="<%=reward.getProject_num() %>"/>
                <input type="hidden" name="reward_num" value="<%=reward.getReward_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.lat.beans.Reward"%>
<%@ 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>insertReward</title>
</head>
<body>
<%
    Reward reward=(Reward)request.getAttribute("reward");
    if(reward==null) reward=new Reward();
%>
<form method="post"
<% if(reward.getProject_num()==0){%>
action="insert"
<% }else{%>
action="update"
<% }%>
>
    <table border="1">
        <tr>
            <td>Project_num</td>
            <td colspan="2">
            <% if(reward.getProject_num()==0){%>
            <input type="text" name="project_num" value="<%=reward.getProject_num() %>"/>
            <% }else{%>
            <input type="hidden" name="project_num" value="<%=reward.getProject_num() %>"/>
                <%=reward.getProject_num()%>
            <% }%>
            </td>
        </tr>
        <tr>
            <td>Reward_num</td>
            <td colspan="2">
            <% if(reward.getReward_num()==0){%>
            <input type="text" name="reward_num" value="<%=reward.getReward_num() %>"/>
            <% }else{%>
            <input type="hidden" name="reward_num" value="<%=reward.getReward_num() %>"/>
                <%=reward.getReward_num()%>
            <% }%>
            </td>
        </tr>
        <tr>
            <td>name</td>
            <td colspan="2"><input type="text" name="name" value="<%=reward.getName()==null?"":reward.getName() %>"/></td>
        </tr>
        <tr>
            <td>price</td> 
            <td colspan="2"><input type="text" name="price" value="<%=reward.getPrice()==0?"":reward.getPrice() %>"/></td>
        </tr>
        <tr>
            <td>item</td>
            <td colspan="2"><input type="text" name="item" value="<%=reward.getItem()==null?"":reward.getItem() %>"/></td>
        </tr>
        <tr>
            <td>min</td>
            <td colspan="2"><input type="text" name="min" value="<%=reward.getMin()==0?"":reward.getMin() %>"/></td>
        </tr>
        <tr>
            <td>
            <%if(reward.getProject_num()==0){%>
                <input type="submit" value="등록"/>
            <%}else{%>
                <input type="submit" value="수정"/>
            <%}%>
                <input type="reset" value="취소"/>
            </td>
            <td>
                <a href="listReward">
                    <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
<%@ 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>listReward</title>
</head>
<body>
    <table border="1">
        <tr>
            <th>project_num</th>
            <th>reward_num</th>
            <th>name</th>
            <th>price</th>
            <th>item</th>
            <th>min</th>
        </tr>
    <c:forEach var="reward" items="${list}">
        <tr>
            <td>
                <a href="detailReward?project_num=${reward.project_num}&reward_num=${reward.reward_num}">
                    ${reward.project_num}
                </a>
            </td>
            <td>${reward.reward_num}</td>
            <td>${reward.name}</td>
            <td>${reward.price}</td>
            <td>${reward.item}</td>
            <td>${reward.min}</td>
        </tr>
    </c:forEach>
        <tr>
            <td colspan="6">
                <a href="insertReward">
                    <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(Exam_AttachFile)  (0) 2017.11.03
CRUD-example(investment)  (0) 2017.11.02
CRUD  (0) 2017.11.02
Posted by 전설의아이
|

CRUD

Legend 개발자/Spring 2017. 11. 2. 11:44

CRUD는 대부분의 컴퓨터 소프트웨어가 가지는 기본적인 데이터 처리 기능인 Create(생성)[INSERT], Read(읽기)[SELECT], Update(갱신)[UPDATE], Delete(삭제)[DELETE]를 묶어서 일컫는 말이다. 사용자 인터페이스가 갖추어야 할 기능(정보의 참조/검색/갱신)을 가리키는 용어로서도 사용된다.

 

CRUD만들기 예:

 

가장먼저 beans를 만든다.

이는 내가 어떤 정보를 넣을 것인지 테이블 각 열의 최상단에 위치한 항목이라고 생각하면 된다.

여기서 중요한 점은 [com.lat.beans] 패키지를 만들어 다양한 beans를 하나의 패키지에 넣어서 관리한다. 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.lat.beans;
 
public class Dept {
 
    private int num;
    private String name;
 
    public int getNum() {
        return num;
    }
 
    public void setNum(int num) {
        this.num = num;
    }
 
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
}
 
cs

 

위에서 만든 beans를 보면

Class 명으로는 Dept(부서)

Dept Class 안에 변수로는 private로 num과 name이 있다. 

SQL에서는 Primary Key, Foreign Key를 통해서 여러 테이블의 관계를 결정하기 때문에

num의 경우 PK라는 것을 알 수가 있다.

private의 경우 public과는 다르게 해당 클래스 내에서만 사용할 수 있으므로

getter & setter를 만들어 다른 곳에서도 Dept Class의 num과 name을 사용할 수 있도록 한다.

 

그 다음으로 알아볼 것은 [com.lat.dao] 패키지이다.

[com.lat.dao] 패키지의 주 역할은 java와 SQL을 연결시키는 것이다.

명명규칙으로 만들고자 하는 Class이름 뒤에 DAO를 붙인다.

이를 위해서 가장 먼저 interface로 DeptDAO와 DeptMapper를 만든다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.lat.dao;
 
import java.util.List;
 
import com.lat.beans.Dept;
 
public interface DeptDAO {
 
    public void insertDept(Dept dept);
 
    public void updateDept(Dept dept);
 
    public void deleteDept(Dept dept);
 
    public Dept detailDept(Dept dept);
 
    public List<Dept> listDept();
 
}
 
cs

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.lat.dao;
 
import java.util.List;
 
import com.lat.beans.Dept;
 
public interface DeptMapper {
 
    public void insertDept(Dept dept);
 
    public void updateDept(Dept dept);
 
    public void deleteDept(Dept dept);
 
    public Dept detailDept(Dept dept);
 
    public List<Dept> listDept();
 
}
 
cs

 

만드는 과정은 interface명만 다르고 안에 내용은 같다.

내용으로는 insert, update, delete, detail&list 가 눈에 띄는데 이는 SQL 쿼리문과 연결시키 위한 밑작업이라는 것을 알 수가 있다.

 

다음으로 만들어야 할 것은 SQL 쿼리 문이다.

이는 Mybatis라는 Framework를 사용했으므로 주 기능은 Spring도 제공하는 JDBC 부분 중 쿼리 부분만 따로 xml로 만들어 관리 및 코딩 효율을 올려주는 역할을 한다.

이를 만들기 위해서 DeptMapper와 똑같은 이름을 가진 xml 파일을 만들어 준다.

 

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
<?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.DeptMapper">
    <resultMap type="Dept" id="DeptResultMap">
        <result property="num" column="NUM" />
        <result property="name" column="NAME" />
    </resultMap>
    <select id="listDept" resultMap="DeptResultMap">
        SELECT num, name
          FROM dept
    </select>
    <select id="detailDept" parameterType="com.lat.beans.Dept"
        resultType="com.lat.beans.Dept">
        SELECT num, name
          FROM dept
         WHERE num=#{num}
    </select>
    <insert id="insertDept" parameterType="com.lat.beans.Dept">
        INSERT INTO dept(num, name)
        VALUES (#{num}, #{name})
    </insert>
    <update id="updateDept" parameterType="com.lat.beans.Dept">
        UPDATE dept 
           SET name=#{name}
          WHERE num=#{num}
    </update>
    <delete id="deleteDept">
        DELETE from dept
         WHERE num=#{num}
    </delete>
</mapper>
cs

 

DeptMapper.xml 을 만들 때 가장 먼저 beans 에 해당하는 항목들을 가져온 후, DAO에서 만든 interface 중 insert, update, delete, detail&list 에 해당하는 쿼리문을 각각 작성해준다.

 

이작업이 완료되면 Mybatis의 쿼리문과 java Spring과 연결시키는 코드를 작성해야 한다.

우선 Class DeptDAOService를 만든다. 명명 규칙으로 DAOService 만 뒤에 붙여주면 된다.

 

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
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.Dept;
 
@Repository
public class DeptDAOService implements DeptDAO {
    @Autowired
    private SqlSession sqlsession;
 
    @Override
    public void insertDept(Dept dept) {
        // TODO Auto-generated method stub
        DeptMapper deptMapper = sqlsession.getMapper(DeptMapper.class);
        deptMapper.insertDept(dept);
    }
 
    @Override
    public void updateDept(Dept dept) {
        // TODO Auto-generated method stub
        DeptMapper deptMapper = sqlsession.getMapper(DeptMapper.class);
        deptMapper.updateDept(dept);
    }
 
    @Override
    public void deleteDept(Dept dept) {
        // TODO Auto-generated method stub
        DeptMapper deptMapper = sqlsession.getMapper(DeptMapper.class);
        deptMapper.deleteDept(dept);
    }
 
    @Override
    public Dept detailDept(Dept dept) {
        // TODO Auto-generated method stub
        DeptMapper deptMapper = sqlsession.getMapper(DeptMapper.class);
        return deptMapper.detailDept(dept);
    }
 
    @Override
    public List<Dept> listDept() {
        // TODO Auto-generated method stub
        DeptMapper deptMapper = sqlsession.getMapper(DeptMapper.class);
        return deptMapper.listDept();
    }
 
}
 
cs

 

DeptDAOService Class는 DeptDAO를 implements(상속)을 받는다.

그 후 Spring인 @Autowired를 통해 SqlSession의  Singleton을 만들어 객체생성의 횟수를 줄여 메모리 사용량을 줄여준다.

implements를 했으므로 interface에 미완성된 부분을 완성시켜주는데 여기서 SQL 쿼리문과 연결시키는 작업을 해준다.

 

이제 기본적인 작업은 끝났고 View단과 Control단만 남았다. 우선 Control단을 먼저 만들어 보자

 

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
104
105
106
107
package com.lat.controller;
 
import java.util.List;
import java.util.Locale;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
 
import com.lat.beans.Dept;
import com.lat.dao.DeptDAOService;
 
@Controller
public class DeptController {
 
    @Autowired
    private DeptDAOService deptDAOService;
 
    @RequestMapping(value = "/dept/listDept")
    public ModelAndView list() {
        List<Dept> list = deptDAOService.listDept();
        ModelAndView view = new ModelAndView("dept/listDept");
        view.addObject("list", list);
        return view;
    }
 
    @RequestMapping(value = "/dept/insertDept")
    public ModelAndView insertDept() {
        ModelAndView view = new ModelAndView("dept/insertDept");
        return view;
    }
 
    @RequestMapping(value = "/dept/insert")
    public String insert(HttpServletRequest request) {
        String num = request.getParameter("num");
        String name = request.getParameter("name");
        Dept dept = new Dept();
        dept.setNum(Integer.parseInt(num));
        dept.setName(name);
        deptDAOService.insertDept(dept);
        return "redirect:listDept";
    }
 
    @RequestMapping(value = "/dept/update")
 
    public String update(HttpServletRequest request) {
        String numVal = request.getParameter("num");
        int num = 0;
        if (numVal != null)
            num = Integer.parseInt(numVal);
        String name = request.getParameter("name");
        Dept dept = new Dept();
        dept.setNum(num);
        dept.setName(name);
        deptDAOService.updateDept(dept);
        return "redirect:listDept";
    }
 
    @RequestMapping(value = "/dept/updateDept")
    public ModelAndView updateDept(HttpServletRequest request) {
        String numVal = request.getParameter("num");
        int num = 0;
        if (numVal != null)
            num = Integer.parseInt(numVal);
        Dept dept = new Dept();
        dept.setNum(num);
        Dept deptRlt = deptDAOService.detailDept(dept);
        ModelAndView view = new ModelAndView("dept/insertDept");
        view.addObject("dept", deptRlt);
        return view;
    }
 
    @RequestMapping(value = "/dept/delete")
    public String deleteDept(HttpServletRequest request) {
        String numVal = request.getParameter("num");
        int num = 0;
        if (numVal != null)
            num = Integer.parseInt(numVal);
        Dept dept = new Dept();
        dept.setNum(num);
        deptDAOService.deleteDept(dept);
        return "redirect:listDept";
    }
 
    @RequestMapping(value = "/dept/detailDept")
    public ModelAndView detail(Locale locale, HttpServletRequest request) {
        String numVal = request.getParameter("num");
        int num = 0;
        if (numVal != null)
            num = Integer.parseInt(numVal);
 
        Dept dept = new Dept();
 
        dept.setNum(num);
 
        ModelAndView result = new ModelAndView();
        Dept deptRlt = deptDAOService.detailDept(dept);
        result.addObject("dept", deptRlt);
        result.setViewName("dept/detailDept");
        return result;
    }
 
}
 
cs

 

간단하게 표하나를 만들고 CRUD에 알맞는 기능을 갖추어 주고, 화면에 Table을 먼저 뿌린 후 행을 추가하는 기능인 insert를 넣었고, num에 PK값을 주었기 때문에 num을 조회하면 update, delete할 수 있도록 만들었다.

 

이 기능대로라면 view단의 경우 1. 메인화면인 Table을 뿌리는 화면, 2. 조회하는 화면, 3. 뿌리는 화면이 필요하다. 그래서 아래와 같이 만들었다.

 

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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.lat.beans.Dept"%>
<%@ 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>detailDept</title>
</head>
<body>
Dept상세보기
<%
    Dept dept=(Dept)request.getAttribute("dept");
    if(dept==null) dept=new Dept();
%>
<table border="1">
    <tr>
        <td>Num</td>
        <td><%=dept.getNum()%></td>
    </tr>
    <tr>
        <td>Name</td>
        <td><%=dept.getName()%></td>
    </tr>
    <tr>
        <td colspan="2">
            <form method="post" action="updateDept">
                <input type="hidden" name="num" value="<%=dept.getNum() %>"/>
                <input type="submit" value="수정"/>
            </form>    
            <form method="post" action="delete">
                <input type="hidden" name="num" value="<%=dept.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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.lat.beans.Dept"%>
<%@ 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>insertDept</title>
</head>
<body>
<%
    Dept dept=(Dept)request.getAttribute("dept");
    if(dept==null) dept=new Dept();
%>
<form method="post" 
<% if(dept.getNum()==0){%>
action="insert"
<% }else{%>
action="update"
<% }%>
>
    <table border="1">
        <tr>
            <td>num</td>
            <td colspan="2">
            <% if(dept.getNum()==0){%>
            <input type="text" name="num" value="<%=dept.getNum()%>"/>
            <%}else{%>
            <input type="hidden" name="num" value="<%=dept.getNum()%>"/>
                <%=dept.getNum()%>
            <% }%>
            </td>
        </tr>
        <tr>
            <td>name</td>
            <td colspan="2"><input type="text" name="name" value="<%=dept.getName()==null?"":dept.getName() %>"/></td>
        </tr>
        <tr>
            <td>
            <%if(dept.getNum()==0){%>
                <input type="submit" value="등록"/>
            <%}else{%>
                <input type="submit" value="수정"/>
            <%}%>
                <input type="reset" value="취소"/>
            </td>
            <td>
                <a href="listDept">
                    <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
<%@ 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>listDept</title>
</head>
<body>
    <table border="1">
        <tr>
            <td>num</td>
            <td>name</td>
        </tr>
    <c:forEach items="${list}" var="dept">    
        <tr>
            <td>
            <a href="detailDept?num=${dept.num}">
                ${dept.num}
            </a>
            </td>
            <td>${dept.name}</td>
        </tr>
    </c:forEach>
        <tr>
            <td colspan="2">
                <a href="insertDept">
                    <input type="button" value="insert"/>
                </a>
            </td>
        </tr>
    </table>
</body>
</html>
cs

 

이제 서버를 가동시켜서 실행을 하면된다.

서버의 경우 무료인 Tomcat을 사용하였고, 개발환경 역시 무료인 Eclipse를 사용했다.

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

CRUD-example(Projectr_AttachFile)  (0) 2017.11.03
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
Posted by 전설의아이
|