Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 데이터베이스
- 버추얼머신
- jsp연결
- 자바
- Cisco
- Oracle
- 정처기필기
- NCS
- 네트워크관리사
- ciscopacket
- 정보처리기사
- rinux
- jsp
- html
- 이것이 자바다
- ospf
- cisco packet
- php
- 라우터
- 원형그래프
- 리눅스
- 오라클
- javaee
- 참조타입
- autoset
- Java
- sql
- w3school
- VLAN
- 네트워크
Archives
- Today
- Total
기록해! 정리해!
myBatis2 (5)- 자료실(사진) 본문
1. 오라클 테이블
Create table psd_img(
idx number(3) not null primary key, -- 테이블에 P.K 만들기
sno char(5) not null, -- examtbl 테이블과 외래키로 연결할 컬럼 만들기
img nvarchar2(30)
) ;
create sequence seq_psd_img;
2.
3. PsdVO
package com.rubypaper.psd;
import org.springframework.web.multipart.MultipartFile;
import lombok.Data;
@Data
public class PsdVO {
private int idx;
private String sno;
private String img; //이름을 저장할 컬럼
//실제 파일을 핸들링할 수 있는 컬럼
private MultipartFile file;
}
4. PsdDao
package com.rubypaper.psd;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface PsdDao {
void insert(PsdVO vo);
List<PsdVO> list();
}
5. PsdController
ExamController에서 잘라온다
package com.rubypaper.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.rubypaper.psd.PsdVO;
@Controller
public class PsdController {
@RequestMapping("/form_psd.do")
String form_psd(PsdVO vo){
System.out.println("==> /form_psd 확인");
return "form_psd";
}
@RequestMapping("/form_psd_ok.do")
String form_psd_ok(PsdVO vo){
System.out.println("==> /form_psd_ok 확인");
return "redirect:index.html";
}
@RequestMapping("/list_psd.do")
String list_psd(PsdVO vo){
System.out.println("==> /list_psd 확인");
return "list_psd.do";
}
}
6. mapper
<?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.rubypaper.psd.PsdDao">
<insert id="insert" parameterType="com.rubypaper.psd.PsdVO" >
insert into psd_img (idx, sno, img)
values(seq_psd_img.nextval, #{sno}, #{img})
</insert>
<select id="list" parameterType="com.rubypaper.psd.PsdVO" resultType="com.rubypaper.psd.PsdVO" >
select * from psd_img
</select>
</mapper>
7. PsdService / PsdServiceImpl
package com.rubypaper.psd;
import java.util.List;
public interface PsdService {
void insert(PsdVO vo);
List<PsdVO> list();
}
package com.rubypaper.psd;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PsdServiceImpl implements PsdService {
@Autowired
private PsdDao dao;
@Override
public void insert(PsdVO vo) {
dao.insert(vo);
}
@Override
public List<PsdVO> list() {
return dao.list();
}
}
8.PsdController
@Autowired 로 서비스 받아준다
package com.rubypaper.controller;
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 com.rubypaper.psd.PsdServiceImpl;
import com.rubypaper.psd.PsdVO;
@Controller
public class PsdController {
@Autowired
private PsdServiceImpl service;
@RequestMapping("/form_psd.do")
String form_psd(PsdVO vo){
System.out.println(" ==> /form_psd 확인 ");
return "form_psd";
}
@RequestMapping("/form_psd_ok.do")
String form_psd_ok(PsdVO vo){
System.out.println(" ==> /form_psd_ok 확인 ");
return "redirect:index.html";
}
@RequestMapping("/list_psd.do")
String list_psd(PsdVO vo, Model model){
System.out.println(" ==> /list_psd.do 확인 ");
model.addAttribute("li", service.list());
return "list_psd";
}
}
9. list_psd.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h2>자료실 목록보기 ( <a href=index.html>처음으로</a> )</h2>
<table border=1 >
<tr align="center">
<th > 순번 </th> <th > 번호 </th> <th> 파일명 </th> <th> 사진 </th>
</tr>
<c:forEach items="${li}" var="m" varStatus="status" >
<tr align="center">
<td> ${status.count} </td>
<td> ${m.sno} </td>
<td> ${m.img}</td>
<td> <img src=./files/${m.img} width=100 height=100 /> </td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>
10. index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h2> 시작페이지 </h2>
<a href=form.do>1.저장하기 </a> <br><br>
<a href=getExamList.do>2.목록보기 </a> <br><br>
<a href=form_psd.do>3.자료실저장 </a> <br><br>
<a href=list_psd.do>4.자료실목록 </a> <br><br>
</div>
</body>
</html>
'SpringBoot' 카테고리의 다른 글
myBatis2 (7)- 자료실(사진삭제, space.jpg) (0) | 2022.10.13 |
---|---|
myBatis2 (6)- 자료실(사진) (0) | 2022.10.13 |
myBatis2 (4)- 자료실(사진) (0) | 2022.10.13 |
myBatis2 (3)- 검색창 (0) | 2022.10.13 |
myBatis2 (2)- 상세보기 (0) | 2022.10.13 |
Comments