BoardController
package com.demo.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/board")
public class BoardController {
@GetMapping("/main")
public String main() {
return "board/main";
}
@GetMapping("/read")
public String read() {
return "board/read";
}
@GetMapping("/write")
public String write() {
return "board/write";
}
@GetMapping("/modify")
public String modify() {
return "board/modify";
}
@GetMapping("/delete")
public String delete() {
return "board/delete";
}
}
미리만들어 둔 html jsp로 만들기
modify.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="root" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>미니 프로젝트</title>
<!-- Bootstrap CDN -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 상단 메뉴 부분 -->
<c:import url="/WEB-INF/views/include/menu.jsp" />
<div class="container" style="margin-top: 100px">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="card shadow">
<div class="card-body">
<form action="board_modify.html" method="post">
<div class="form-group">
<label for="board_writer_name">작성자</label> <input type="text"
id="board_writer_name" name="board_writer_name"
class="form-control" value="홍길동" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_date">작성날짜</label> <input type="text"
id="board_date" name="board_date" class="form-control"
value="2018-7-20" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_subject">제목</label> <input type="text"
id="board_subject" name="board_subject" class="form-control"
value="제목입니다" />
</div>
<div class="form-group">
<label for="board_content">내용</label>
<textarea id="board_content" name="board_content"
class="form-control" rows="10" style="resize: none">본문입니다</textarea>
</div>
<div class="form-group">
<label for="board_file">첨부 이미지</label> <img src="image/logo.png"
width="100%" /> <input type="file" name="board_file"
id="board_file" class="form-control" accept="image/*" />
</div>
<div class="form-group">
<div class="text-right">
<button type="submit" class="btn btn-primary">수정완료</button>
<a href="board_read.html" class="btn btn-info">취소</a>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
<!-- 하단 메뉴 부분 -->
<c:import url="/WEB-INF/views/include/footer.jsp" />
</body>
</html>
read.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="root" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>미니 프로젝트</title>
<!-- Bootstrap CDN -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 상단 메뉴 부분 -->
<c:import url="/WEB-INF/views/include/menu.jsp" />
<div class="container" style="margin-top: 100px">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="card shadow">
<div class="card-body">
<div class="form-group">
<label for="board_writer_name">작성자</label> <input type="text"
id="board_writer_name" name="board_writer_name"
class="form-control" value="홍길동" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_date">작성날짜</label> <input type="text"
id="board_date" name="board_date" class="form-control"
value="2018-7-20" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_subject">제목</label> <input type="text"
id="board_subject" name="board_subject" class="form-control"
value="제목입니다" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_content">내용</label>
<textarea id="board_content" name="board_content"
class="form-control" rows="10" style="resize: none"
disabled="disabled">본문입니다</textarea>
</div>
<div class="form-group">
<label for="board_file">첨부 이미지</label> <img
src="${root}/resources/image/logo.png" width="100%" />
</div>
<div class="form-group">
<div class="text-right">
<a href="board_main.html" class="btn btn-primary">목록보기</a> <a
href="board_modify.html" class="btn btn-info">수정하기</a> <a
href="board_main.html" class="btn btn-danger">삭제하기</a>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
<!-- 하단 메뉴 부분 -->
<c:import url="/WEB-INF/views/include/footer.jsp" />
</body>
</html>
write.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="root" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>미니 프로젝트</title>
<!-- Bootstrap CDN -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" />
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<!-- 상단 메뉴 부분 -->
<c:import url="/WEB-INF/views/include/menu.jsp" />
<div class="container" style="margin-top: 100px">
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="card shadow">
<div class="card-body">
<div class="form-group">
<label for="board_writer_name">작성자</label> <input type="text"
id="board_writer_name" name="board_writer_name"
class="form-control" value="홍길동" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_date">작성날짜</label> <input type="text"
id="board_date" name="board_date" class="form-control"
value="2018-7-20" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_subject">제목</label> <input type="text"
id="board_subject" name="board_subject" class="form-control"
value="제목입니다" disabled="disabled" />
</div>
<div class="form-group">
<label for="board_content">내용</label>
<textarea id="board_content" name="board_content"
class="form-control" rows="10" style="resize: none"
disabled="disabled">본문입니다</textarea>
</div>
<div class="form-group">
<label for="board_file">첨부 이미지</label> <img
src="${root}/resources/image/logo.png" width="100%" />
</div>
<div class="form-group">
<div class="text-right">
<a href="board_main.html" class="btn btn-primary">목록보기</a> <a
href="board_modify.html" class="btn btn-info">수정하기</a> <a
href="board_main.html" class="btn btn-danger">삭제하기</a>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3"></div>
</div>
</div>
<!-- 하단 메뉴 부분 -->
<c:import url="/WEB-INF/views/include/footer.jsp" />
</body>
</html>
delete.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<script>
alert('삭제되었습니다')
location.href='${root}board/main'
</script>
테스트
이미지 오류
이미지 폴더를 resources 폴더에 넣음
mapping주소를 "/**"로 변경
resources폴더안에 있는 image에서 찾음
테스트하기
index.jsp에서
더보기 눌렀을 경우 board/main으로 이동하게 경로 설정해줌
더보기(main페이지) 에서 글쓰기 누르면 글쓰기( board/wirte )로 이동하게끔 경로 수정
read.jsp에서 목록/ 수정/삭제 버튼에도 링크 수정해주기
.
delete.jsp
'BACKEND > Spring' 카테고리의 다른 글
게시판 만들기 2- VO생성 및 MyBatis 설정 , 인터셉터 설정 (0) | 2023.10.26 |
---|---|
게시판 만들기 2 - 테이블 만들기(DB) (0) | 2023.10.26 |
게시판 만들기 2 - context path, user(login,logout,modify,join.jsp) (1) | 2023.10.26 |
게시판 만들기 2 - 기본 설정 및 include(nav,footer 분리) (0) | 2023.10.26 |
게시판 만들기 2 - MVC의 구조 (0) | 2023.10.26 |