쌤이 준 파일 resources 파일에 갖다 붙히기
3개 우클릭한 후 노트패드로 열기
spring2_board_list 복사해서
noticeboard 폴더에 list.jsp 에 갖다붙이기
<!-- Tiles 라이브러리 의존관계 등록 시작 -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>3.0 .8 </version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0 .8 </version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>3.0 .8 </version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0 .8 </version>
</dependency>
<!-- Tiles 라이브러리 의존관계 등록 끝 -->
메이븐 -> 프로젝트 업데이트
kr.or.ddit.controller.tiles 패키지 만든후 TilesSettingsController 클래스
만듬
그다음
<!-- Tiles bean 등록 진행 : Tiles를 이용한 페이지 모듈화 -->
<beans:bean id="tilesViewResolver"
class ="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.tiles3.TilesView" />
<beans:property name="order" value="1" />
</beans:bean>
<beans:bean id="tilesConfigurer"
class ="org.springframework.web.servlet.view.tiles3.TilesConfigurer" >
<beans:property name="definitions" >
<beans:list>
<beans:value>/WEB-INF/spring/tiles-config.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<!-- Tiles를 이용한 페이지 설정 끝 -->
추가 해준다
구글에 tiles dtd 검색
tiles-config.xml에 저 한줄을 복붙하면 <tiles만 쳐도 태그 자동완성할수 있다.
<?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="mainTemplate" template="/WEB-INF/views/mainTemplate.jsp" >
<put-attribute name="header" value="/WEB-INF/views/tiles/header.jsp" />
<put-attribute name="footer" value="/WEB-INF/views/tiles/footer.jsp" />
</definition>
<definition name="notice/*" extends="mainTemplate" >
<put-attribute name="content" value="/WEB-INF/views/noticeboard/{1}.jsp" />
</definition>
</tiles-definitions>
views 폴더에 mainTemplate.jsp 만들고 list에 붙였던 전체를 자르고 갖다 붙힌다.
그다음 views 폴더에 tiles 폴더를 만들고 header.jsp 와 footer.jsp 만들고
각각 그 영역에 맞는 코드를 mainTemplate.jsp에 갖다 붙이고
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8" >
<meta name="viewport" content="width=device-width, initial-scale=1" >
<title>AdminLTE 3 | Simple Tables</title>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback" >
<link rel="stylesheet"
href="../../plugins/fontawesome-free/css/all.min.css" >
<link rel="stylesheet" href="../../dist/css/adminlte.min.css" >
</head>
<body class ="hold-transition sidebar-mini" >
<div class ="wrapper" >
<!-- header 영역 -->
<tiles:insertAttribute name="header" />
<div class ="content-wrapper" >
<tiles:insertAttribute name="content" />
</div>
<!-- footer 영역 -->
<tiles:insertAttribute name="footer" ></tiles:insertAttribute>
<aside class ="control-sidebar control-sidebar-dark" ></aside>
</div>
<script src="../../plugins/jquery/jquery.min.js" ></script>
<script src="../../plugins/bootstrap/js/bootstrap.bundle.min.js" ></script>
<script src="../../dist/js/adminlte.min.js" ></script>
</body>
</html>
../../에 ${pageContext.request.contextPath }/resources/ 추가해줌
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8" >
<meta name="viewport" content="width=device-width, initial-scale=1" >
<title>AdminLTE 3 | Simple Tables</title>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback" >
<link rel="stylesheet"
href="${pageContext.request.contextPath }/resources/plugins/fontawesome-free/css/all.min.css" >
<link rel="stylesheet" href="${pageContext.request.contextPath }/resources/dist/css/adminlte.min.css" >
</head>
<body class ="hold-transition sidebar-mini" >
<div class ="wrapper" >
<!-- header 영역 -->
<tiles:insertAttribute name="header" />
<div class ="content-wrapper" >
<tiles:insertAttribute name="content" />
</div>
<!-- footer 영역 -->
<tiles:insertAttribute name="footer" />
<aside class ="control-sidebar control-sidebar-dark" ></aside>
</div>
<script src="${pageContext.request.contextPath }/resources/plugins/jquery/jquery.min.js" ></script>
<script src="${pageContext.request.contextPath }/resources/plugins/bootstrap/js/bootstrap.bundle.min.js" ></script>
<script src="${pageContext.request.contextPath }/resources/dist/js/adminlte.min.js" ></script>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<nav class ="main-header navbar navbar-expand navbar-white navbar-light" >
<ul class ="navbar-nav" >
<li class ="nav-item" ><a class ="nav-link" data-widget="pushmenu"
href="#" role="button" ><i class ="fas fa-bars" ></i></a></li>
</ul>
</nav>
<aside class ="main-sidebar sidebar-dark-primary elevation-4" >
<a href="" class ="brand-link" >
<img src="${pageContext.request.contextPath }/resources/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
class ="brand-image img-circle elevation-3" style="opacity: .8" >
<span class ="brand-text font-weight-light" >SPRING</span>
</a>
<div class ="sidebar" >
<div class ="user-panel mt-3 pb-3 mb-3 d-flex" >
<div class ="image" >
<img src="${pageContext.request.contextPath }/resources/dist/img/user2-160x160.jpg"
class ="img-circle elevation-2" alt="User Image" >
</div>
<div class ="info" >
<a href="#" class ="d-block" >DDIT Spring</a>
</div>
</div>
<nav class ="mt-2" >
<ul class ="nav nav-pills nav-sidebar flex-column"
data-widget="treeview" role="menu" data-accordion="false" >
<!-- Add icons to the links using the .nav-icon class
with font -awesome or any other icon font library -->
<li class ="nav-item" ><a href="#" class ="nav-link" > <i
class ="nav-icon fas fa-tachometer-alt" ></i>
<p>공지사항</p>
</a></li>
</ul>
</nav>
</div>
</aside>
footer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<footer class ="main-footer" >
<div class ="float-right d-none d-sm-block" >
<b>Version</b> 1.0 .0
</div>
<strong>Copyright © 2014 -2021 <a href="#" >DDIT
SPRING</a>.
</strong> All rights reserved.
</footer>
noticeboard 폴더에 form.jsp와 detail.jsp 추가
NoticeRetrieveController .java에서
package kr.or.ddit.controller.crud.notice;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Controller
@RequestMapping("/notice")
public class NoticeRetrieveController {
@RequestMapping(value="/list.do" , method = RequestMethod.GET)
public String noticeList () {
log.info("noticeList 실행" );
return "notice/list" ;
}
@RequestMapping(value="/detail.do" , method = RequestMethod.GET)
public String noticeDetail () {
log.info("noticeDetail() 실행" );
return "notice/detail" ;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<section class ="content" >
<div class ="row" >
<div class ="col-md-12" >
<div class ="card card-dark" >
<div class ="card-header" >
<h3 class ="card-title" >공지사항 등록</h3>
<div class ="card-tools" >
</div>
</div>
<div class ="card-body" >
<div class ="form-group" >
<label for ="inputName" >제목을 입력해주세요</label>
<input type="text" id="inputName" class ="form-control" placeholder="제목을 입력해주세요" >
</div>
<div class ="form-group" >
<label for ="inputDescription" >내용을 입력해주세요</label>
<textarea id="inputDescription" class ="form-control" rows="14" ></textarea>
</div>
<div class ="form-group" >
<div class ="custom-file" >
<input type="file" class ="custom-file-input" id="customFile" multiple="multiple" >
<label class ="custom-file-label" for ="customFile" >파일을 선택해주세요</label>
</div>
</div>
</div>
<div class ="card-footer bg-white" >
<ul class ="mailbox-attachments d-flex align-items-stretch clearfix" >
<li>
<span class ="mailbox-attachment-icon" ><i class ="far fa-file-pdf" ></i></span>
<div class ="mailbox-attachment-info" >
<a href="#" class ="mailbox-attachment-name" ><i class ="fas fa-paperclip" ></i> Sep2014-report.pdf</a>
<span class ="mailbox-attachment-size clearfix mt-1" >
<span>1 ,245 KB</span>
<a href="#" class ="btn btn-default btn-sm float-right" ><i class ="fas fa-times" ></i></a>
</span>
</div>
</li>
<li>
<span class ="mailbox-attachment-icon" ><i class ="far fa-file-word" ></i></span>
<div class ="mailbox-attachment-info" >
<a href="#" class ="mailbox-attachment-name" ><i class ="fas fa-paperclip" ></i> App Description.docx</a>
<span class ="mailbox-attachment-size clearfix mt-1" >
<span>1 ,245 KB</span>
<a href="#" class ="btn btn-default btn-sm float-right" ><i class ="fas fa-times" ></i></a>
</span>
</div>
</li>
<li>
<span class ="mailbox-attachment-icon has-img" ><img src="${pageContext.request.contextPath }/resources/ dist/img/photo1.png" alt="Attachment" ></span>
<div class ="mailbox-attachment-info" >
<a href="#" class ="mailbox-attachment-name" ><i class ="fas fa-camera" ></i> photo1.png</a>
<span class ="mailbox-attachment-size clearfix mt-1" >
<span>2.67 MB</span>
<a href="#" class ="btn btn-default btn-sm float-right" ><i class ="fas fa-times" ></i></a>
</span>
</div>
</li>
<li>
<span class ="mailbox-attachment-icon has-img" ><img src="${pageContext.request.contextPath }/resources/ dist/img/photo2.png" alt="Attachment" ></span>
<div class ="mailbox-attachment-info" >
<a href="#" class ="mailbox-attachment-name" ><i class ="fas fa-camera" ></i> photo2.png</a>
<span class ="mailbox-attachment-size clearfix mt-1" >
<span>1.9 MB</span>
<a href="#" class ="btn btn-default btn-sm float-right" ><i class ="fas fa-times" ></i></a>
</span>
</div>
</li>
</ul>
</div>
<div class ="card-footer bg-white" >
<div class ="row" >
<div class ="col-12" >
<input type="button" value="목록" class ="btn btn-secondary float-right" >
<input type="button" value="등록" class ="btn btn-dark float-right" >
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<section class ="content-header" >
<div class ="container-fluid" >
<div class ="row mb-2" >
<div class ="col-sm-6" >
<h1>공지사항 상세보기</h1>
</div>
<div class ="col-sm-6" >
<ol class ="breadcrumb float-sm-right" >
<li class ="breadcrumb-item" ><a href="#" >DDIT HOME</a></li>
<li class ="breadcrumb-item active" >공지사항 상세보기</li>
</ol>
</div>
</div>
</div>
</section>
<section class ="content" >
<div class ="container-fluid" >
<div class ="row" >
<div class ="col-md-12" >
<div class ="card card-dark" >
<div class ="card-header" >
<h3 class ="card-title" >제목입니다!!</h3>
<div class ="card-tools" >
관리자 2022 -12 -12 12 :11 1456
</div>
</div>
<form id="quickForm" novalidate="novalidate" >
<div class ="card-body" >내용입니다.</div>
<div class ="card-footer bg-white" >
<ul class ="mailbox-attachments d-flex align-items-stretch clearfix" >
<li>
<span class ="mailbox-attachment-icon" >
<i class ="far fa-file-pdf" ></i>
</span>
<div class ="mailbox-attachment-info" >
<a href="#" class ="mailbox-attachment-name" >
<i class ="fas fa-paperclip" ></i>
파일명
</a>
<span class ="mailbox-attachment-size clearfix mt-1" >
<span>파일 Fancy사이즈 KB</span>
<a href="다운로드 url" >
<span class ="btn btn-default btn-sm float-right" >
<i class ="fas fa-download" ></i>
</span>
</a>
</span>
</div>
</li>
</ul>
</div>
<div class ="card-footer" >
<button type="submit" class ="btn btn-secondary" >목록</button>
<button type="submit" class ="btn btn-dark" >수정</button>
<button type="submit" class ="btn btn-danger" >삭제</button>
</div>
</form>
</div>
</div>
<div class ="col-md-6" ></div>
</div>
</div>
</section>
-- notice 테이블 만들기
create table notice( bo_no number(8) not null, bo_title varchar2(300) not null, bo_content varchar2(4000) not null, bo_writer varchar2(150) not null, bo_date date not null, bo_hit number(8) default 0 null, constraint pk_notice primary key(bo_no) ); create sequence seq_notice increment by 1 start with 1 nocache;
create table noticemember( mem_no number(8) not null, mem_id varchar2(100) not null, mem_pw VARCHAR2(100) not null, mem_name VARCHAR2(100) not null, mem_gender VARCHAR2(30) not null, mem_email VARCHAR2(150) not null, mem_phone VARCHAR2(150) not null, mem_postcode VARCHAR2(30) not null, mem_address1 VARCHAR2(300) not null, mem_address2 VARCHAR2(300) not null, mem_agree VARCHAR2(30) not null, mem_profileimg VARCHAR2(500) not null, mem_regdate date not null, enabled VARCHAR2(2) not null, CONSTRAINT pk_noticemember primary key(mem_no) ); create sequence seq_noticemember increment by 1 start with 1 nocache; create table noticemember_auth( mem_no number(8) not null, auth varchar2(50) not null, constraint fk_noticemember_auth_mem_no foreign key(mem_no) references noticemember(mem_no) );
-- noticefile 테이블 만들기 create table noticefile( file_no number(8) not null, bo_no number(8) not null, file_name varchar2(500) not null, file_size number(20) not null, file_fancysize varchar2(100) not null, file_savepath varchar2(500) not null, file_downcount number(8) not null, constraint pk_noticefile primary key(file_no), CONSTRAINT fk_noticefile_bo_no foreign key(bo_no) references notice(bo_no) ); create sequence seq_noticefile increment by 1 start with 1 nocache;
압축해제 후 파일을 resources 파일 에 복붙한다.
--------pom.xml -->StringUtils 관련
<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.6</version> </dependency>
package kr.or.ddit.controller.crud.notice;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
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 kr.or.ddit.ServiceResult;
import kr.or.ddit.service.INoticeService;
import kr.or.ddit.vo.crud.NoticeVO;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Controller
@RequestMapping("/notice")
public class NoticeInsertController {
@Inject
private INoticeService noticeService;
@RequestMapping(value="/form.do", method = RequestMethod.GET)
public String noticeForm () {
log.info("noticeForm 실행" );
return "notice/form" ;
}
@RequestMapping(value="/insert.do", method=RequestMethod.POST)
public String insertNotice (NoticeVO noticeVO, Model model) {
String goPage = "" ;
Map<String, String> errors = new HashMap<String, String>();
if (StringUtils.isBlank(noticeVO.getBoTitle())) {
errors.put("boTitle" , "제목을 입력해주세요!" );
}
if (StringUtils.isBlank(noticeVO.getBoContent())) {
errors.put("boContent" , "내용을 입력해주세요!" );
}
if (errors.size() >0 ) {
model.addAttribute("errors" , errors);
model.addAttribute("noticeVo" , noticeVO);
}else {
noticeVO.setBoWriter("a001" );
ServiceResult result =noticeService.insertNotice(noticeVO);
if (result.equals(ServiceResult.OK)) {
goPage="redirect:/notice/detail.do?boNo=" +noticeVO.getBoNo();
}else {
model.addAttribute("noticeVO" , noticeVO);
model.addAttribute("message" ,"서버에러, 다시시도해주세요" );
goPage ="notice/form" ;
}
}
return goPage;
}
}
package kr.or.ddit.controller.crud.notice;
import javax.inject.Inject;
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 kr.or.ddit.service.INoticeService;
import kr.or.ddit.vo.crud.NoticeVO;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Controller
@RequestMapping("/notice")
public class NoticeRetrieveController {
@Inject
private INoticeService noticeService;
@RequestMapping(value="/list.do" , method = RequestMethod.GET)
public String noticeList () {
log.info("noticeList 실행" );
return "notice/list" ;
}
@RequestMapping(value="/detail.do" , method = RequestMethod.GET)
public String noticeDetail (int boNo, Model model) {
log.info("noticeDetail() 실행" );
NoticeVO noticeVO = noticeService.selectNotice(boNo);
model.addAttribute("notice" , noticeVO);
return "notice/detail" ;
}
}
package kr.or.ddit.service;
import kr.or.ddit.ServiceResult;
import kr.or.ddit.vo.crud.NoticeVO;
public interface INoticeService {
public ServiceResult insertNotice (NoticeVO noticeVO) ;
public NoticeVO selectNotice (int boNo) ;
}
package kr.or.ddit.service.impl;
import javax.inject.Inject;
import org.springframework.stereotype.Service;
import kr.or.ddit.ServiceResult;
import kr.or.ddit.mapper.INoticeMapper;
import kr.or.ddit.service.INoticeService;
import kr.or.ddit.vo.crud.NoticeVO;
@Service
public class NoticeServiceImpl implements INoticeService {
@Inject
private INoticeMapper noticeMapper;
@Override
public ServiceResult insertNotice (NoticeVO noticeVO) {
ServiceResult result = null ;
int status = noticeMapper.insertNotice(noticeVO);
if (status > 0 ) {
result=ServiceResult.OK;
}else {
result = ServiceResult.FAILED;
}
return result;
}
@Override
public NoticeVO selectNotice (int boNo) {
noticeMapper.incrementHit(boNo);
return noticeMapper.selectNotice(boNo);
}
}
package kr.or.ddit.mapper;
import kr.or.ddit.vo.crud.NoticeVO;
public interface INoticeMapper {
public int insertNotice (NoticeVO noticeVO) ;
public void incrementHit (int boNo) ;
public NoticeVO selectNotice (int boNo) ;
}
<?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="kr.or.ddit.mapper.INoticeMapper" >
<insert id="insertNotice" parameterType="noticeVO" useGeneratedKeys="true" >
<selectKey keyProperty="boNo" resultType="int" order="BEFORE" >
select seq_notice.nextval from dual
</selectKey>
insert into notice (
bo_no, bo_title, bo_content, bo_writer, bo_date
) values (
#{boNo}, #{boTitle}, #{boContent}, #{boWriter}, sysdate
)
</insert>
<update id ="incrementHit" parameterType="int" >
update notice
set
bo_hit = bo_hit + 1
where bo_no = #{bo_no}
</update>
<select id="selectNotice" parameterType="int" resultType="noticeVO" >
select
bo_no, bo_title, bo_content, bo_writer, bo_date, bo_hit
from notice
where bo_no = #{boNo}
</select>
<update id="updateNotice" parameterType="noticeVO" >
update notice
set
bo_title = #{boTitle},
bo_content = #{boContent},
bo_date = sysdate
where bo_no = #{boNo}
</update>
</mapper>
mybatisAlias.xml에
<typeAlias type="kr.or.ddit.vo.crud.NoticeVO" alias="noticeVO"/> 추가