본문 바로가기

Spring

자료실 스프링

pdslist.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<table class="list_table" style="width: 85%">
<colgroup>
	<col width="50"><col width="100"><col width="300"><col width="50">
	<col width="50"><col width="50"><col width="100"><col width="50">
</colgroup>

<thead>
<tr>
	<th>번호</th><th>작성자</th><th>제목</th><th>다운로드</th>
	<th>조회수</th><th>다운수</th><th>작성일</th><th>삭제</th>
</tr>
</thead>

<tbody>

<c:forEach var="pds" items="${pdslist }" varStatus="vs">

<tr>
	<th>${vs.count }</th>
	<td>${pds.id }</td>
	<td style="text-align: left;">
		<a href="pdsdetail.do?seq=${pds.seq }">
			${pds.title }
		</a>
	</td>
	<td>
		<input type="button" name="btnDown" value="다운로드"
			onclick="filedown('${pds.filename}', '${pds.seq}')">
	</td>
	<td>${pds.readcount }</td>
	<td>${pds.downcount }</td>
	<td>
		<font size="1">${pds.regdate }</font>
	</td>
	<td>		
		<img alt="" src="image/del.png" data_file_seq="${pds.seq}"
			class="btn_fileDelete">
	</td>
</tr>
</c:forEach>
</tbody>
</table>

<!-- 추가버튼 -->
<div id="button.wrap">
	<span class="button blue">
		<button type="button" id="_btnAdd">자료추가</button>	
	</span>
</div>

<!-- 다운로드 버튼을 클릭 -->
<form name="file_Down" action="fileDownload.do" method="post">
	<input type="hidden" name="filename">
	<input type="hidden" name="seq">
</form>

<!-- 삭제를 클릭했을 때 -->

<script>
$("#_btnAdd").click(function(){
	location.href = "pdswrite.do";	
});

function filedown(filename, seq){
	let doc = document.file_Down;
	doc.filename.value = filename;
	doc.seq.value = seq;
	doc.submit();  
}

$(".btn_fileDelete").click(function(){
	alert('btn_fileDelete');
});

</script>

 

 

 

 

 

pdswrite.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<form name="frmForm" id="_frmForm" action="pdsupload.do" method="post"
	enctype="multipart/form-data">

<table class="list_table">

<tr>
	<th>아이디</th>
	<td style="text-align: left">
		<input type="text" name="id" readonly="readonly"
			value="${login.id}" size="50">
	</td>
</tr>

<tr>
	<th>제목</th>
	<td style="text-align: left;">
		<input type="text" name="title" size="50">
	</td>
</tr>

<tr>
	<th>파일 업로드</th>
	<td style="text-align: left">
		<input type="file" name="fileload" style="width: 400px">
	</td>
</tr>

<tr>
	<th>내용</th>
	<td style="text-align: left;">
		<textarea rows="10" cols="50" name="content"></textarea>
	</td>
</tr>

<tr>
	<td colspan="2" style="height: 50px;text-align: center;">
		<a href="#none" id="_btnPds" title="자료올리기">
			<img alt="" src="image/bwrite.png">
		</a>
	</td>
</tr>
</table>
	
</form>

<script>
$("#_btnPds").click(function(){
	// alert('click');
	
	// 제목, 내용, 빈칸 검사 

	$("#_frmForm").submit();
});

</script>

 

 

 

 

 

pdsdetail.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<table class="list_table" style="width: 85%">
<colgroup>
	<col width="200"><col width="500">
</colgroup>

<tr>
	<th>아이디</th>
	<td style="text-align: left;">${pds.id }</td>
</tr>

<tr>
	<th>제목</th>
	<td style="text-align: left;">${pds.title }</td>
</tr>

<tr>
	<th>다운로드</th>
	<td style="text-align: left;">
		<input type="button" name="btnDown" value="다운로드"
			onclick="filedowns('${pds.filename}', '${pds.seq }')">
	</td>
</tr>

<tr>
	<th>조회수</th>
	<td style="text-align: left;">${pds.readcount }</td>
</tr>

<tr>
	<th>다운수</th>
	<td style="text-align: left;">${pds.downcount }</td>
</tr>

<tr>
	<th>파일명</th>
	<td style="text-align: left;">${pds.filename }</td>
</tr>

<tr>
	<th>등록일</th>
	<td style="text-align: left;">${pds.regdate }</td>
</tr>

<tr>
	<th>내용</th>
	<td style="text-align: left;">
		<textarea rows="10" cols="50">${pds.content }</textarea>
	</td>
</tr>
</table>

<!-- 수정하기 -->
<c:if test="${login.id eq pds.id }">
<div id="buttons_wrap">
	<span class="button blue">
		<button type="button" id="_btnUpdate">수정하기</button>
	</span>
</div>
</c:if>

<!-- seq만 필요하므로 -->
<form name="frmForm" id="_frmForm" action="pdsupdate.do" method="post">
	<input type="hidden" name="seq" value="${pds.seq }">
</form>


<script>
function filedowns(filename, seq){
	location.href = "fileDownload.do?filename=" + filename + "&seq=" + seq;	
}	

$("#_btnUpdate").click(function () {
	$("#_frmForm").submit();
});

</script> 

 

 

 

 

 

 

 

 

 

 

pdsupdate.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<form name="frmForm" id="_frmForm" action="pdsupdateAf.do"
	method="post" enctype="multipart/form-data">
<input type="hidden" name="seq" value="${pds.seq}">

<table class="list_table" style="width: 85%">
<colgroup>
	<col width="200"><col width="500">
</colgroup>

<tr>
	<th>아이디</th>
	<td style="text-align: left;">${pds.id}</td>
</tr>

<tr>
	<th>제목</th>
	<td style="text-align: left;">
		<input type="text" name="title" size="50" value="${pds.title}">
	</td>
</tr>

<tr>
	<th>파일 업로드</th>
	<td style="text-align: left;">
		<!-- 기존의 파일 -->
		<input type="text" name="namefile" value="${pds.filename}" size="50" readonly="readonly">
		<!-- 수정할 파일 -->
		<input type="file" name="fileload" style="width: 400px">		
	</td>
</tr>

<tr>
	<th>내용</th>
	<td style="text-align: left;">
		<textarea rows="10" cols="50" name="content" id="_content">${pds.content}</textarea>
	</td>
</tr>

<tr>
	<td colspan="2" style="height: 50px; text-align: center;">
		<span class="button blue">
			<a href="#none" id="btnupdate" title="수정완료">
				수정하기
			</a>
		</span>
	</td>
</tr>

</table>	
</form>

<script>
$("#btnupdate").click(function(){
	$("#_frmForm").submit();
});

</script>

 

 

 

 

 

layouts-tiles.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%-- request.setCharacterEncoding("utf-8"); --%>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:requestEncoding value="utf-8"/>

<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<tiles:insertAttribute name="header"/>

<link rel="stylesheet" type="text/css" 
	href="<%=request.getContextPath() %>/css/style.css">
	
</head>
<body>

<div id="body_wrap">
	<div id="main_wrap">
		<tiles:insertAttribute name="top_inc"/>
		<tiles:insertAttribute name="top_menu"/>
	</div>

	<div id="middle_wrap">
		<div id="sidebar_wrap">
			<tiles:insertAttribute name="left_menu"/>
		</div>
		
		<div id="content_wrap">
			<div id="content_title_wrap">
				<div class="title">${doc_title }</div>	
			</div>
						
			<tiles:insertAttribute name="main"/>
				
		</div>		
	</div>
	
	<div id="footer_wrap">
		<tiles:insertAttribute name="bottom_inc"/>
	</div>
</div>

<script type="text/javascript">
$(document).ready(function(){
	$("#content_title_wrap div.title").css("background-image", "url('./image/ico_sub_sb.gif')");
});

</script>

</body>
</html>

 

 

 

 

 

 

 

layouts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

<definition name="login.tiles" template="/WEB-INF/views/login/login.jsp">
</definition>

<definition name="regi.tiles" template="/WEB-INF/views/login/regi.jsp">
</definition>

<definition name="bbslist.tiles" template="/WEB-INF/views/layouts-tiles.jsp">
	<put-attribute name="header" value="/WEB-INF/views/commons/header.jsp"/>
	<put-attribute name="top_inc" value="/WEB-INF/views/commons/top_inc.jsp"/>
	<put-attribute name="top_menu" value="/WEB-INF/views/commons/top_menu.jsp"/>	
	<put-attribute name="left_menu" value="/WEB-INF/views/bbs/left_bbslist.jsp"/>
	<put-attribute name="main" value="/WEB-INF/views/bbs/bbslist.jsp"/>	
	<put-attribute name="bottom_inc" value="/WEB-INF/views/commons/bottom_inc.jsp"/>
</definition>

<definition name="bbswrite.tiles" extends="bbslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/bbs/bbswrite.jsp"/>
</definition>

<definition name="bbsdetail.tiles" extends="bbslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/bbs/bbsdetail.jsp"/>
</definition>

<definition name="answer.tiles" extends="bbslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/bbs/bbsreply.jsp"/>
</definition>

<definition name="bbsupdate.tiles" extends="bbslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/bbs/bbsupdate.jsp"/>
</definition>


<definition name="bbslist2.tiles" extends="bbslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/bbs2/bbslist2.jsp"/>
</definition>

<definition name="sessionOut.tiles" extends="bbslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/login/sessionOut.jsp"/>
</definition>


<!-- calendar -->
<definition name="calendar.tiles" extends="bbslist.tiles">
	<put-attribute name="left_menu" value="/WEB-INF/views/calendar/left_calendar.jsp"/>
	<put-attribute name="main" value="/WEB-INF/views/calendar/calendar.jsp"/>
</definition>


<!-- calendarplug -->
<definition name="calendarpluglist.tiles" extends="bbslist.tiles">
	<put-attribute name="left_menu" value="/WEB-INF/views/calendar/left_calendar.jsp"/>
	<put-attribute name="main" value="/WEB-INF/views/calendarplug/calendarpluglist.jsp"/>
</definition>

<definition name="calwrite.tiles" extends="calendar.tiles">
	<put-attribute name="main" value="/WEB-INF/views/calendar/calwrite.jsp"/>
</definition>

<definition name="caldetail.tiles" extends="calendar.tiles">
	<put-attribute name="main" value="/WEB-INF/views/calendar/caldetail.jsp"/>
</definition>

<!-- pds -->
<definition name="pdslist.tiles" extends="bbslist.tiles">
	<put-attribute name="left_menu" value="/WEB-INF/views/pds/left_pds.jsp"/>
	<put-attribute name="main" value="/WEB-INF/views/pds/pdslist.jsp"/>
</definition>

<definition name="pdswrite.tiles" extends="pdslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/pds/pdswrite.jsp"/>
</definition>

<definition name="pdsdetail.tiles" extends="pdslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/pds/pdsdetail.jsp"/>
</definition>

<definition name="pdsupdate.tiles" extends="pdslist.tiles">
	<put-attribute name="main" value="/WEB-INF/views/pds/pdsupdate.jsp"/>
</definition>

</tiles-definitions>

 

 

 

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>springSampleAll</groupId>
  <artifactId>springSampleAll</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
  
  <dependencies>
  
  	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-webmvc</artifactId>
	    <version>5.2.7.RELEASE</version>
	</dependency>  
	
	<dependency>
	    <groupId>log4j</groupId>
	    <artifactId>log4j</artifactId>
	    <version>1.2.17</version>
	</dependency>
	
	<dependency>
	    <groupId>org.slf4j</groupId>
	    <artifactId>slf4j-simple</artifactId>
	    <version>1.7.25</version>	    
	</dependency>
  
  	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>servlet-api</artifactId>
		<version>2.5</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>javax.servlet.jsp</groupId>
		<artifactId>jsp-api</artifactId>
		<version>2.1</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>jstl</artifactId>
		<version>1.2</version>
	</dependency>
	
	<!-- 런타임에 동적으로 자바 클래스의 프록시(대리(인))를 생성해주는 기능을 제공한다 -->
	<dependency>
	    <groupId>cglib</groupId>		
	    <artifactId>cglib</artifactId>
	    <version>3.3.0</version>
	</dependency>
	<dependency>
	    <groupId>commons-digester</groupId>
	    <artifactId>commons-digester</artifactId>
	    <version>1.8</version>
	</dependency>
	
	<dependency>
  		<groupId>commons-logging</groupId>
  		<artifactId>commons-logging</artifactId>
  		<version>1.1.3</version>
  	</dependency>
  	
  	<!-- Ajax 사용 설정[jackson] -->
  	<dependency>
  		<groupId>org.codehaus.jackson</groupId>	
  		<artifactId>jackson-core-asl</artifactId>
  		<version>1.9.12</version>
  	</dependency>
  	<dependency>
  		<groupId>org.codehaus.jackson</groupId>
  		<artifactId>jackson-mapper-asl</artifactId>
  		<version>1.9.12</version>
  	</dependency>
  	
  	<!-- 의존성을 추가 --> 
  	<dependency>
  		<groupId>javax.inject</groupId>
  		<artifactId>javax.inject</artifactId>
  		<version>1</version>
  	</dependency>
  	
  	<!-- JCL(자카르타 커먼스 로깅)을 사용 --> 	
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>jcl-over-slf4j</artifactId>
  		<version>1.7.30</version>
  	</dependency>

	<!-- XML 파싱 -->
  	<dependency>
	    <groupId>jdom</groupId>
	    <artifactId>jdom</artifactId>
	    <version>1.0</version>
	</dependency>
	
	<!-- 마이 바티스 스프링 사용시 -->
  	<dependency>
	    <groupId>org.mybatis</groupId>
	    <artifactId>mybatis-spring</artifactId>
	    <version>2.0.3</version>
	</dependency>
	
  	<dependency>
	    <groupId>org.mybatis</groupId>
	    <artifactId>mybatis</artifactId>
	    <version>3.5.3</version>
	</dependency>
	
	<!-- 마이 SQL 사용시 -->	
  	<dependency>
	    <groupId>mysql</groupId>
	    <artifactId>mysql-connector-java</artifactId>
	    <version>8.0.18</version>
	</dependency>
	
	<!-- XML 파싱 -->
  	<dependency>
	    <groupId>org.jdom</groupId>
	    <artifactId>jdom</artifactId>
	    <version>2.0.1</version>
	</dependency>

	<!-- SLF4J API를 사용하도록 -->
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-api</artifactId>
  		<version>1.7.30</version>
  	</dependency>

	<!-- log4j -->
  	<!-- <dependency>
  		<groupId>ant</groupId>
  		<artifactId>ant-apache-log4j</artifactId>
  		<version>1.9.4</version>
  	</dependency> -->
  	
  	<dependency>
	    <groupId>commons-dbcp</groupId>
	    <artifactId>commons-dbcp</artifactId>
	    <version>1.4</version>
	</dependency>
  	
  	<!-- Map을 Bean객체로 바꾸어주는 클래스 -->
  	<dependency>
  		<groupId>commons-beanutils</groupId>
  		<artifactId>commons-beanutils-core</artifactId>
  		<version>1.8.2</version>
  	</dependency>
  	
  	<!-- DBCP : DB Connection Poll 사용 --> 
  	<dependency>
  		<groupId>com.kenai.nbpwr</groupId>
  		<artifactId>org-apache-commons-dbcp</artifactId>
  		<version>1.2.2-201002241055</version>
  		<type>nbm</type>
  	</dependency>
  	
  	<!-- IO 기능 개발을 지원하는 유틸리티 라이브러리  다운안됨 -->
  	<dependency>
  		<groupId>org.apache.commons</groupId>
  		<artifactId>commons-io</artifactId>
  		<version>1.3.2</version>
  	</dependency>
  	
  	<dependency>
  		<groupId>org.apache.commons</groupId>
  		<artifactId>commons-lang3</artifactId>
  		<version>3.9</version>
  	</dependency>
  	
  	<dependency>
  		<groupId>org.apache.commons</groupId>
  		<artifactId>commons-pool2</artifactId>
  		<version>2.8.0</version>
  	</dependency>
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-log4j12</artifactId>
  		<version>1.7.30</version>
  	</dependency>
  	
  	<!-- spring -->
	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-aop</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-beans</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>  	
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context-support</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>  	
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-core</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-expression</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-jdbc</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-orm</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-test</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-tx</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-web</artifactId>
  		<version>5.2.7.RELEASE</version>
  	</dependency>
  	
  	<!-- Java용 json 라이브러리(XML/YAM/CSV) data-processing 툴 -->
  	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-core</artifactId>
	    <version>2.10.1</version>
	</dependency>
	
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-databind</artifactId>
	    <version>2.10.1</version>
	</dependency>
		
	
	
	<dependency>
	    <groupId>org.aspectj</groupId>
	    <artifactId>aspectjweaver</artifactId>
	    <version>1.9.4</version>
	</dependency>
	
	<dependency>
	    <groupId>org.aspectj</groupId>
	    <artifactId>aspectjrt</artifactId>
	    <version>1.9.4</version>
	</dependency>
	
	<!-- oracle -->
	<dependency>
	    <groupId>com.oracle.database.jdbc</groupId>
	    <artifactId>ojdbc6</artifactId>
	    <version>11.2.0.4</version>
	</dependency>
	
	
	<dependency>
	    <groupId>org.json</groupId>
	    <artifactId>json</artifactId>
	    <version>20190722</version>
	</dependency>
	
	<!-- tiles -->
	<dependency>
	    <groupId>org.apache.tiles</groupId>
	    <artifactId>tiles-api</artifactId>
	    <version>3.0.7</version>
	</dependency>
	
	<dependency>
	    <groupId>org.apache.tiles</groupId>
	    <artifactId>tiles-core</artifactId>
	    <version>3.0.7</version>
	</dependency>
	
	<dependency>
	    <groupId>org.apache.tiles</groupId>
	    <artifactId>tiles-jsp</artifactId>
	    <version>3.0.7</version>
	</dependency>
	
	<dependency>
	    <groupId>org.apache.tiles</groupId>
	    <artifactId>tiles-servlet</artifactId>
	    <version>3.0.7</version>
	</dependency>
	
	<dependency>
	    <groupId>org.apache.tiles</groupId>
	    <artifactId>tiles-template</artifactId>
	    <version>3.0.7</version>
	</dependency>
	
	<dependency>
  		<groupId>org.apache.tiles</groupId>
  		<artifactId>tiles-autotag-core-runtime</artifactId>
  		<version>1.1.0</version>
  	</dependency>

	<dependency>
  		<groupId>org.apache.tiles</groupId>
  		<artifactId>tiles-request-api</artifactId>
  		<version>1.0.6</version>
  	</dependency>
  	
  	<dependency>
  		<groupId>org.apache.tiles</groupId>
  		<artifactId>tiles-request-jsp</artifactId>
  		<version>1.0.6</version>
  	</dependency>
  	
  	<dependency>
  		<groupId>org.apache.tiles</groupId>
  		<artifactId>tiles-request-servlet</artifactId>
  		<version>1.0.6</version>
  	</dependency> 
  	
  	<dependency>
	    <groupId>commons-fileupload</groupId>
	    <artifactId>commons-fileupload</artifactId>
	    <version>1.3.3</version>
	</dependency>
  
  </dependencies>		  
   
<repositories>
  	<repository>
		<id>codelds</id>		<!-- ojdbc6 와 함께 추가 -->
		<url>https://code.lds.org/nexus/content/groups/main-repo</url>
	</repository>
</repositories> 
  
  
</project>

 

 

 

 

 

 

 

 

 

 

 

 

 

pds.xml

<?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="Pds">

<select id="getPdsList" resultType="bit.com.a.dto.PdsDto">
	SELECT SEQ, ID, TITLE, CONTENT, FILENAME, OLDFILENAME, 
		READCOUNT, DOWNCOUNT, REGDATE
	FROM PDS
	ORDER BY SEQ DESC
</select>

<insert id="uploadPds" parameterType="bit.com.a.dto.PdsDto">
	INSERT INTO PDS(SEQ, ID, TITLE, CONTENT, FILENAME, OLDFILENAME, READCOUNT, DOWNCOUNT, REGDATE)
	VALUES(SEQ_PDS.NEXTVAL, #{id}, #{title}, #{content}, #{filename}, #{oldfilename}, 0, 0, SYSDATE)
</insert>

<select id="getPds" parameterType="java.lang.Integer"
	resultType="bit.com.a.dto.PdsDto">
	SELECT SEQ, ID, TITLE, CONTENT, FILENAME, OLDFILENAME, 
		READCOUNT, DOWNCOUNT, REGDATE
	FROM PDS
	WHERE SEQ=#{seq}
</select>


<update id="updatepds" parameterType="bit.com.a.dto.PdsDto">
	UPDATE PDS
	SET TITLE=#{title}, CONTENT=#{content}, FILENAME=#{filename}, REGDATE=SYSDATE
	WHERE SEQ=#{seq}
</update>


</mapper>

 

 

 

 

 

 

 

 

 

PdsUtil.java

package bit.com.a.util;

import java.util.Date;

import org.springframework.dao.DataAccessResourceFailureException;

public class PdsUtil {
	
	// myfile.txt => f.indexOf('.') -> 6
	// 파일명,  확장자명
	// f.substring( 6 ) => .txt
	// f.substring( 0, 6 ) => myfile
	
	// myfile.txt -> 322432432432.txt	
	public static String getNewFileName(String f) {
		String filename = "";
		String fpost = "";
		
		if(f.indexOf('.') >= 0) {	// 확장자명이 있음
			fpost = f.substring( f.indexOf('.') );	// .txt
			filename = new Date().getTime() + fpost;	// 43325432243.txt
		}
		else {
			filename = new Date().getTime() + ".back";
		}
		
		return filename;
	}

}

 

 

 

 

 

 

 

 

 

PdsDao.java

package bit.com.a.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FileUtils;
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.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import bit.com.a.dto.PdsDto;
import bit.com.a.service.PdsService;
import bit.com.a.util.PdsUtil;

@Controller
public class PdsController {
	
	@Autowired
	PdsService service;
	
	@RequestMapping(value = "pdslist.do", method = {RequestMethod.GET, RequestMethod.POST})
	public String pdslist(Model model) {
		model.addAttribute("doc_title", "자료실 목록");
		
		List<PdsDto> list = service.getPdsList();
		model.addAttribute("pdslist", list);
		
		return "pdslist.tiles";
	}
	
	@RequestMapping(value = "pdswrite.do", method = {RequestMethod.GET, RequestMethod.POST})
	public String pdswrite(Model model) {
		model.addAttribute("doc_title", "자료 올리기");
		
		return "pdswrite.tiles";
	}
	
	@RequestMapping(value = "pdsupload.do", method = {RequestMethod.GET, RequestMethod.POST})
	public String pdsupload(PdsDto pdsdto, 
					@RequestParam(value = "fileload", required = false)MultipartFile fileload, 
					HttpServletRequest req) {
		
		// filename 취득
		String filename = fileload.getOriginalFilename();
		pdsdto.setOldfilename(filename);
		
		// upload 경로 설정
		// server
		String fupload = req.getServletContext().getRealPath("/upload");
		
		// 폴더
	//	String fupload = "d:\\tmp";
		
		System.out.println("fupload:" + fupload);
		
		// file명을 취득
		String f = pdsdto.getOldfilename();
		String newfilename = PdsUtil.getNewFileName( f );	// 324324324324.txt
		
		pdsdto.setFilename(newfilename);
		
		File file = new File(fupload + "/" + newfilename);
				
		try {
			// 실제로 파일이 업로드되는 부분
			FileUtils.writeByteArrayToFile(file, fileload.getBytes());
			
			// db에 저장
			service.uploadPds(pdsdto);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	 
		
		return "redirect:/pdslist.do";		
	}
	
	// fileDownload.do
	@RequestMapping(value = "fileDownload.do", method = {RequestMethod.GET, RequestMethod.POST})
	public String fileDownload(String filename, int seq, HttpServletRequest req, Model model) {
		
		// 경로
		// server
		String fupload = req.getServletContext().getRealPath("/upload");
		
		// 폴더
	//	String fupload = "d:\\tmp";
		
		File downloadFile = new File(fupload + "/" + filename);
		
		model.addAttribute("downloadFile", downloadFile);		
		model.addAttribute("seq", seq);
		
		return "downloadView";
	}
	
	@RequestMapping(value = "pdsdetail.do", method= {RequestMethod.GET, RequestMethod.POST})
	public String pdsdetail(int seq, Model model) {
		model.addAttribute("doc_title", "자료 보기");
				
		// dto 취득
		PdsDto pdsdto = service.getPds(seq);
		model.addAttribute("pds", pdsdto);
		
		return "pdsdetail.tiles";
	}
	
	@RequestMapping(value = "pdsupdate.do", method= {RequestMethod.GET, RequestMethod.POST})
	public String pdsupdate(int seq, Model model) {
		model.addAttribute("doc_title", "자료 수정");
		
		// dto 취득
		PdsDto pdsdto = service.getPds(seq);
		model.addAttribute("pds", pdsdto);
		
		return "pdsupdate.tiles";
	}
	
	@RequestMapping(value = "pdsupdateAf.do", method= {RequestMethod.GET, RequestMethod.POST})
	public String pdsupdateAf(	PdsDto pdsdto, 
								String namefile,	// 기존의 파일 명,
								HttpServletRequest req,
								@RequestParam(value = "fileload", required = false)MultipartFile fileload) {
		
		pdsdto.setOldfilename(fileload.getOriginalFilename());
		
		// 파일 경로
		String fupload = req.getServletContext().getRealPath("/upload");
		
		// 수정할 파일이 있음
		if(pdsdto.getOldfilename() != null && !pdsdto.getOldfilename().equals("")) {
			
			String f = pdsdto.getOldfilename();
			String newfilename = PdsUtil.getNewFileName(f);
			
			pdsdto.setFilename(newfilename);
			
			File file = new File(fupload + "/" + newfilename);			
			
			try {
				// 실제 업로드
				FileUtils.writeByteArrayToFile(file, fileload.getBytes());
				
				// db 경신
				service.updatePds(pdsdto);		
				
			} catch (IOException e) {				
				e.printStackTrace();
			}			
		}
		else {	// 수정할 파일 없음
			
			// 기존의 파일명으로 설정
			pdsdto.setFilename(namefile);
			
			// DB
			service.updatePds(pdsdto);	
		}
		
		return "redirect:/pdslist.do";
	}	
	
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PdsDto.java

package bit.com.a.dto;

import java.io.Serializable;
/*
DROP TABLE PDS
CASCADE CONSTRAINTS;

DROP SEQUENCE SEQ_PDS;

CREATE TABLE PDS(
	SEQ NUMBER(8) PRIMARY KEY,
	ID VARCHAR2(50) NOT NULL,
	TITLE VARCHAR2(200) NOT NULL,
	CONTENT VARCHAR2(4000) NOT NULL,
	FILENAME VARCHAR2(50) NOT NULL,
	OLDFILENAME VARCHAR2(50) NOT NULL,
	READCOUNT NUMBER(8) NOT NULL,
	DOWNCOUNT NUMBER(8) NOT NULL,
	REGDATE DATE NOT NULL
);

CREATE SEQUENCE SEQ_PDS
START WITH 1
INCREMENT BY 1;

ALTER TABLE PDS
ADD CONSTRAINT FK_PDS_ID FOREIGN KEY(ID)
REFERENCES MEMBER(ID);
*/
public class PdsDto implements Serializable {

	private int seq;
	private String id;
	
	private String title;
	private String content;
	
	private String filename;	
	private String oldfilename;
	
	private int readcount;
	private int downcount;
	
	private String regdate; 
	
	public PdsDto() {
	}

	public PdsDto(int seq, String id, String title, String content, String filename, String oldfilename, int readcount,
			int downcount, String regdate) {
		super();
		this.seq = seq;
		this.id = id;
		this.title = title;
		this.content = content;
		this.filename = filename;
		this.oldfilename = oldfilename;
		this.readcount = readcount;
		this.downcount = downcount;
		this.regdate = regdate;
	}

	public PdsDto(String id, String title, String content, String filename) {
		super();
		this.id = id;
		this.title = title;
		this.content = content;
		this.filename = filename;
	}

	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public String getOldfilename() {
		return oldfilename;
	}

	public void setOldfilename(String oldfilename) {
		this.oldfilename = oldfilename;
	}

	public int getReadcount() {
		return readcount;
	}

	public void setReadcount(int readcount) {
		this.readcount = readcount;
	}

	public int getDowncount() {
		return downcount;
	}

	public void setDowncount(int downcount) {
		this.downcount = downcount;
	}

	public String getRegdate() {
		return regdate;
	}

	public void setRegdate(String regdate) {
		this.regdate = regdate;
	}

	@Override
	public String toString() {
		return "PdsDto [seq=" + seq + ", id=" + id + ", title=" + title + ", content=" + content + ", filename="
				+ filename + ", oldfilename=" + oldfilename + ", readcount=" + readcount + ", downcount=" + downcount
				+ ", regdate=" + regdate + "]";
	}
	
	
	
}

 

 

 

 

 

 

 

 

 

 

PdsDao.java

package bit.com.a.dao;

import java.util.List;

import bit.com.a.dto.PdsDto;

public interface PdsDao {

	List<PdsDto> getPdsList();	
	boolean uploadPds(PdsDto dto);	
	PdsDto getPds(int seq);
	
	boolean updatePds(PdsDto dto);
}

 

 

 

 

 

 

PdsDaoImpl.java

package bit.com.a.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import bit.com.a.dao.PdsDao;
import bit.com.a.dto.PdsDto;

@Repository
public class PdsDaoImpl implements PdsDao {

	@Autowired
	SqlSession sqlSession;
	
	String ns = "Pds.";

	@Override
	public List<PdsDto> getPdsList() {		
		return sqlSession.selectList(ns + "getPdsList");
	}

	@Override
	public boolean uploadPds(PdsDto dto) {
		int n = sqlSession.insert(ns + "uploadPds", dto);
		return n>0?true:false;
	}
	
	@Override
	public PdsDto getPds(int seq) {		
		return sqlSession.selectOne(ns + "getPds", seq);		
	}

	@Override
	public boolean updatePds(PdsDto dto) {
		int n = sqlSession.update(ns + "updatepds", dto);
		return n>0?true:false;
	}	
}

 

 

 

 

 

 

 

 

 

PdsService.java

package bit.com.a.service;

import java.util.List;

import bit.com.a.dto.PdsDto;

public interface PdsService {

	List<PdsDto> getPdsList();	
	boolean uploadPds(PdsDto dto);	
	PdsDto getPds(int seq);
	
	boolean updatePds(PdsDto dto);
}

 

 

 

 

 

 

 

 

 

 

 

 

PdsServiceImpl.java

package bit.com.a.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bit.com.a.dao.PdsDao;
import bit.com.a.dto.PdsDto;
import bit.com.a.service.PdsService;

@Service
public class PdsServiceImpl implements PdsService {
	
	@Autowired
	PdsDao dao;

	@Override
	public List<PdsDto> getPdsList() {		
		return dao.getPdsList();
	}

	@Override
	public boolean uploadPds(PdsDto dto) {		
		return dao.uploadPds(dto);
	}

	@Override
	public PdsDto getPds(int seq) {		
		return dao.getPds(seq);		
	}

	@Override
	public boolean updatePds(PdsDto dto) {		
		return dao.updatePds(dto);		
	}

	
}





 

 

 

'Spring' 카테고리의 다른 글

투표  (0) 2020.09.15
tiles 타일즈로 화면넘기기(예)  (0) 2020.09.09
ajax  (0) 2020.09.09
페이지네이션 pagination 파일  (0) 2020.09.09
페이징/서치/search jsp로 불러오기  (0) 2020.09.09