본문 바로가기
수업내용

20230628 수업내용🫡🫡🫡

by titlejjk 2023. 6. 28.

jQuery에 대한 복습!

 

$(선택자).동작함수1().동작함수2()

달러($) 기호는 제이쿼리를 의미하고, 제이쿼리에 접근할 수 있게 해주는 식별자이다.

- 선택자를 이용하여 원하는 HTML 요소를 선택하고,

- 동작 함수를 정의하여 선택된 요소에 원하는 동작을 설정한다.

/test_jquery/Step02_ajax.jsp

 

$는 함수이면서 object로도 사용이 가능하다.

Oracle DB에서 연결 연산잦는 +  가 아니고 || 파이프문자 2개이다

'kim' + 'gura' = X
'kim || 'gura' = O

File(자료실)게시판을 만들 dao/daoImpl

package com.gura.spring04.file.dao;

import java.util.List;

import com.gura.spring04.file.dto.FileDto;

public interface FileDao {
	public void insert(FileDto dto);
	public FileDto getData(int num);
	public void delete(int num);
	public List<FileDto> getList(FileDto dto);
	public int getCount(FileDto dto);
}
package com.gura.spring04.file.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.gura.spring04.file.dto.FileDto;

@Repository
public class FileDaoImpl implements FileDao{
	
	@Autowired
	private SqlSession session;

	@Override
	public void insert(FileDto dto) {
		session.insert("file.insert", dto);
	}

	@Override
	public FileDto getData(int num) {
		
		return session.selectOne("file.getData", num);
	}

	@Override
	public void delete(int num) {
		session.delete("file.delete", num);
	}

	@Override
	public List<FileDto> getList(FileDto dto) {
		
		return session.selectList("file.getList", dto);
	}

	@Override
	public int getCount(FileDto dto) {
		
		return session.selectOne("file.getCount", dto);
	}

}

FileController 만들어주기

package com.gura.spring04.file.controller;

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.gura.spring04.file.dto.FileDto;
import com.gura.spring04.file.service.FileService;

@Controller
public class FileController {

	@Autowired
	private FileService service;
	
	   @RequestMapping("/file/list")
	   public String list(HttpServletRequest request) {
	      
	      service.getList(request);
	      
	      return "file/list";
	   }
	   
	   @RequestMapping("/file/upload_form")
	   public String uploadForm() {
	      
	      return "file/upload_form";
	   }
	   
	   @RequestMapping("/file/upload")
	   public ModelAndView upload(FileDto dto, ModelAndView mView, HttpServletRequest request) {
	      service.saveFile(dto, mView, request);
	      mView.setViewName("file/upload");
	      return mView;
	   }
	   
	   @RequestMapping("/file/download")
	   public ModelAndView download(int num, ModelAndView mView) {
	      service.getFileData(num, mView);
	      // 응답을 할 bean 의 이름을 설정 
	      mView.setViewName("fileDownView");
	      return mView;
	   }
	   
	   @RequestMapping("/file/delete")
	   public ModelAndView delete(int num, ModelAndView mView, HttpServletRequest request) {
	      service.deleteFile(num, request);
	      mView.setViewName("redirect:/file/list");
	      return mView;
	   }
}

자료실 게시판 조회/검색 list.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>/views/file/list.jsp</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
</head>
<body>
	<div class="container">
		<a href="${pageContext.request.contextPath }/file/upload_form">업로드 하기</a>
		<h3>자료실 목록 보기</h3>
		<table class="table table-striped">
			<thead class="table-dark">
				<tr>
					<th>번호</th>
					<th>작성자</th>
					<th>제목</th>
					<th>파일명</th>
					<th>크기</th>
					<th>등록일</th>
					<th>삭제</th>
				</tr>
			</thead>
			<tbody>
			<c:forEach var="tmp" items="${list }">
				<tr>
					<td>${tmp.num }</td>
					<td>${tmp.writer }</td>
					<td>${tmp.title }</td>
					<td>
						<a href="download?num=${tmp.num }">${tmp.orgFileName }</a>
					</td>
					<td>${tmp.fileSize }</td>
					<td>${tmp.regdate }</td>
					<td>
						<c:if test="${tmp.writer eq sessionScope.id }">
							<a href="javascript:deleteConfirm(${tmp.num })">삭제</a>
						</c:if>
					</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
		<nav>
			<ul class="pagination">
				<%--
					startPageNum 이 1 이 아닌 경우에만 Prev 링크를 제공한다. 
					&condition=${condition}&keyword=${encodedK}
				 --%>
				<c:if test="${startPageNum ne 1 }">
					<li class="page-item">
						<a class="page-link" href="list?pageNum=${startPageNum-1 }&condition=${condition}&keyword=${encodedK}">Prev</a>
					</li>
				</c:if>
				<c:forEach var="i" begin="${startPageNum }" end="${endPageNum }">
					<li class="page-item ${pageNum eq i ? 'active' : '' }">
						<a class="page-link" href="list?pageNum=${i }&condition=${condition}&keyword=${encodedK}">${i }</a>
					</li>
				</c:forEach>
				<%--
					마지막 페이지 번호가 전체 페이지의 갯수보다 작으면 Next 링크를 제공한다. 
				 --%>
				<c:if test="${endPageNum lt totalPageCount }">
					<li class="page-item">
						<a class="page-link" href="list?pageNum=${endPageNum+1 }&condition=${condition}&keyword=${encodedK}">Next</a>
					</li>
				</c:if>
			</ul>
		</nav>
		<!-- 검색 폼 -->
		<form action="list" method="get">
			<label for="condition">검색조건</label>	
			<select name="condition" id="condition">
				<option value="title_filename" ${condition eq 'title_filename' ? 'selected' : '' }>제목 + 파일명</option>
				<option value="title" ${condition eq 'title' ? 'selected' : '' }>제목</option>
				<option value="writer" ${condition eq 'writer' ? 'selected' : '' }>작성자</option>
			</select>
			<input type="text" name="keyword" placeholder="검색어..." value="${keyword }"/>
			<button type="submit">검색</button>
		</form>
		<c:if test="${not empty condition }">
			<p>
				<strong>${totalRow }</strong> 개의 자료가 검색 되었습니다.
				<a href="list">리셋</a>
			</p>
		</c:if>
	</div>
	<script>
		function deleteConfirm(num){
			let isDelete=confirm("삭제 하시겠습니까?");
			if(isDelete){
				location.href="delete?num="+num;
			}
		}
	</script>
</body>
</html>

FileMapper검색기능 추가SELECT문

<select id="getData" parameterType="int" resultType="fileDto">
      SELECT num,writer,title,orgFileName,saveFileName,fileSize,regdate
      FROM board_file
      WHERE num=#{num}
   </select>
   <delete id="delete" parameterType="int">
      DELETE FROM board_file
      WHERE num=#{num}
   </delete>
   <select id="getList" parameterType="fileDto" 
      resultType="fileDto">
      
      SELECT *
      FROM
         (SELECT result1.*, ROWNUM AS rnum
         FROM
            (SELECT num,writer,title,orgFileName,saveFileName,
               fileSize,regdate
            FROM board_file        
            <choose>
      			<when test="title != null and orgFileName != null">
      			WHERE title LIKE '%'||#{title}||'%' OR orgFileName LIKE '%' ||#{orgFileName}||'%'
      			</when>
      			<when test="title != null">
      			WHERE title LIKE '%'||#{title}||'%'
      			</when>
      			<when test="writer != null">
      			WHERE writer LIKE '%'||#{writer}||'%'
      			</when>
      		</choose>    
            ORDER BY num DESC) result1)
      WHERE rnum BETWEEN #{startRowNum} AND #{endRowNum}
   </select>
   <select id="getCount" parameterType="fileDto" resultType="int">
      SELECT NVL(MAX(ROWNUM), 0)
      FROM board_file
      <choose>
      	<when test="title != null and orgFileName != null">
      		WHERE title LIKE '%'||#{title}||'%' OR orgFileName LIKE '%' ||#{orgFileName}||'%'
      	</when>
      	<when test="title != null">
      		WHERE title LIKE '%'||#{title}||'%'
      	</when>
      	<when test="writer != null">
      		WHERE writer LIKE '%'||#{writer}||'%'
      	</when>
      </choose>
   </select>

 

 

너무 길어서 2장으로..

댓글