일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 자바연산자
- spring crud
- jsp 날짜팝업
- 2020정보처리기사실기
- 자바기초
- 정처기실기정리
- 스프링 crud
- 게시판만들기
- 오라클설치
- jsp 팝업띄우기
- 프로그래머스 MYSQL
- 스프링 CRUD게시판
- 오버라이딩
- 자바 정규표현식 예제
- 자바배열예제
- 2020정보처리기사실기요약
- html기초
- jsp게시판만들기
- crud게시판
- PLSQL
- spring crud게시판
- CRUD게시판만들기
- Oracle기초
- js datepicker
- 2020정보처리기사실기정리
- 스프링게시판만들기
- 프로그래머스 SQL
- 프로그래머스 쿼리문
- 날짜지정팝업
- 정보처리기사실기정리
Archives
- Today
- Total
영보의 SystemOut.log
[Spring] Spring Transaction 답변 게시판 만들기 (2) 본문
반응형
qh5944.tistory.com/110?category=418956
앞선 포스팅에 이어서 계속 해보겠습니다.
경로 입니다!
예제
# BoardController.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package com.sist.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.*;
import com.sist.dao.*;
@Controller
public class BoardController {
@Autowired
private BoardDAO dao;
@GetMapping("board/list.do")
public String board_list(String page,Model model)
{
if(page==null)
page="1";
int curpage=Integer.parseInt(page);
Map map=new HashMap();
int rowSize=15;
int start=(rowSize*curpage)-(rowSize-1);
int end=rowSize*curpage;
map.put("start", start);
map.put("end", end);
List<BoardVO> list=dao.boardListData(map);
// JSP로 전송
model.addAttribute("list", list);
return "board/list";
}
@GetMapping("board/insert.do")
public String board_insert()
{
return "board/insert";
}
@PostMapping("board/insert_ok.do")
public String board_insert_ok(@ModelAttribute("vo") BoardVO vo)
{
dao.boardInsert(vo);
return "redirect:list.do";
}
@GetMapping("board/detail.do")
public String board_detail(int no,Model model)
{
//Model => 해당 JSP로 데이터 전송
// 데이터베이스 연동
BoardVO vo=dao.boardDetailData(no);
// 데이터 전송
model.addAttribute("vo", vo);
return "board/detail";
}
@GetMapping("board/reply.do")
public String board_reply(int no,Model model)
{
model.addAttribute("no", no);
return "board/reply";
}
/*
* <a> , location.href="" => GetMapping
* <form> => PostMapping
*/
@PostMapping("board/reply_ok.do")
public String board_reply_ok(int pno,BoardVO vo)
{
dao.boardReplyInsert(pno, vo);
return "redirect:../board/list.do";
}
}
|
cs |
# MemberController.java
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
32
33
34
|
package com.sist.web;
import javax.servlet.http.HttpSession;
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.sist.dao.MemberDAO;
// Session,Cookie
@Controller
public class MemberController {
@Autowired
private MemberDAO dao;
@RequestMapping("member/login.do")
public String member_login()
{
return "member/login";
}
@RequestMapping("member/login_ok.do")
public String member_login_ok(String id,String pwd,HttpSession session,Model model)
{
String result=dao.isLogin(id, pwd);
if(result.equals("OK"))
{
session.setAttribute("id", id);
}
model.addAttribute("result", result);
return "member/login_ok";
}
}
|
cs |
# login.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row {
margin: 0px auto;
width:350px;
}
</style>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function(){
$('.btn').click(function(){
let id=$('#id').val();
if(id.trim()=="")
{
$('#id').focus();
return;
}
let pwd=$('#pwd').val();
if(pwd.trim()=="")
{
$('#pwd').focus();
return;
}
// 전송
$('#frm').submit();
});
});
</script>
</head>
<body>
<div class="container">
<div class="row">
<h1 class="text-center">Login</h1>
<form method="post" action="login_ok.do" id=frm>
<table class="table">
<tr>
<td width=20% class="text-right">ID</td>
<td width=80%>
<input type=text name=id size=15 id=id>
</td>
</tr>
<tr>
<td width=20% class="text-right">PW</td>
<td width=80%>
<input type=password name=pwd size=15 id=pwd>
</td>
</tr>
<tr>
<td colspan="2" class="text-center">
<input type=button value="로그인" class="btn btn-sm btn-primary">
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
|
cs |
- 로그인 화면
# login_ok.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:choose>
<c:when test="${result=='NOID' }">
<script>
alert("ID가 존재하지 않습니다!!");
history.back();
</script>
</c:when>
<c:when test="${result=='NOPWD' }">
<script>
alert("비밀번호가 틀립니다!!");
history.back();
</script>
</c:when>
<c:otherwise>
<c:redirect url="../board/list.do"/>
</c:otherwise>
</c:choose>
|
cs |
- 로그인 반드시 해야 글 쓸 수 있음
# list.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row {
margin: 0px auto;
width:800px;
}
.btd {
font-size: 8pt;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<h3 class="text-center">자유게시판</h3>
<c:if test="${sessionScope.id!=null }">
<table class="table">
<tr>
<td class="text-left">
<a href="insert.do" class="btn btn-sm btn-danger">새글</a>
</td>
</tr>
</table>
</c:if>
<table class="table table-striped">
<tr class="warning">
<th class="text-center" width=10%>번호</th>
<th class="text-center" width=45%>제목</th>
<th class="text-center" width=15%>이름</th>
<th class="text-center" width=20%>작성일</th>
<th class="text-center" width=10%>조회수</th>
</tr>
<c:forEach var="vo" items="${list }">
<tr>
<td class="text-center btd" width=10%>${vo.no }</td>
<td class="text-left btd" width=45%>
<c:if test="${vo.getGt()>0 }">
<c:forEach var="i" begin="1" end="${vo.getGt() }">
</c:forEach>
▶
</c:if>
<a href="detail.do?no=${vo.no }">${vo.subject }</a>
</td>
<td class="text-center btd" width=15%>${vo.name }</td>
<td class="text-center btd" width=20%>
<fmt:formatDate value="${vo.regdate }" pattern="yyyy-MM-dd"/></td>
<td class="text-center btd" width=10%>${vo.hit }</td>
</tr>
</c:forEach>
</table>
<table class="table">
<tr>
<td class="text-left"></td>
<td class="text-right">
<a href="#" class="btn btn-sm btn-primary">이전</a>
${curpage } page / ${totalpage } pages
<a href="#" class="btn btn-sm btn-primary">다음</a>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
|
cs |
- 메인(?) 게시판 리스트가 나오는 폼
# insert.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row {
margin: 0px auto;
width:700px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<h3 class="text-center">글쓰기</h3>
<form method="post" action="insert_ok.do">
<table class="table table-hover">
<tr>
<th class="danger text-right" width=15%>이름</th>
<td width=85%>
<input type=text name=name size=15 class="input-sm">
</td>
</tr>
<tr>
<th class="danger text-right" width=15%>제목</th>
<td width=85%>
<input type=text name=subject size=45 class="input-sm">
</td>
</tr>
<tr>
<th class="danger text-right" width=15%>내용</th>
<td width=85%>
<textarea rows="10" cols="50" name=content></textarea>
</td>
</tr>
<tr>
<th class="danger text-right" width=15%>비밀번호</th>
<td width=85%>
<input type=password name=pwd size=10 class="input-sm">
</td>
</tr>
<tr>
<td colspan="2" class="text-center">
<input type=submit value=글쓰기 class="btn btn-sm btn-primary">
<input type=button value=취소 class="btn btn-sm btn-primary"
onclick="javascript:history.back()"
>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
|
cs |
- 글 쓰기 폼
# detail.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row {
margin: 0px auto;
width:700px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<h1 class="text-center">내용보기</h1>
<table class="table table-striped">
<tr>
<th width=20% class="text-center danger">번호</th>
<td width=30% class="text-center">${vo.no }</td>
<th width=20% class="text-center danger">작성일</th>
<td width=30% class="text-center">
<fmt:formatDate value="${vo.regdate }" pattern="yyyy-MM-dd"/>
</td>
</tr>
<tr>
<th width=20% class="text-center danger">이름</th>
<td width=30% class="text-center">${vo.name }</td>
<th width=20% class="text-center danger">조회수</th>
<td width=30% class="text-center">${vo.hit }</td>
</tr>
<tr>
<th width=20% class="text-center danger">제목</th>
<td colspan="3">${vo.subject }</td>
</tr>
<tr>
<td colspan="4" class="text-left" valign="top" height="200">${vo.content }</td>
</tr>
<tr>
<td colspan="4" class="text-right">
<c:if test="${sessionScope.id!=null }">
<a href="../board/reply.do?no=${vo.no }" class="btn btn-xs btn-danger">답변</a>
<a href="#" class="btn btn-xs btn-success">수정</a>
<a href="#" class="btn btn-xs btn-info">삭제</a>
</c:if>
<a href="../board/list.do" class="btn btn-xs btn-warning">목록</a>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
|
cs |
- 상세페이지 화면
# reply.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<style type="text/css">
.row {
margin: 0px auto;
width:700px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<h3 class="text-center">답변하기</h3>
<form method="post" action="reply_ok.do">
<table class="table table-hover">
<tr>
<th class="danger text-right" width=15%>이름</th>
<td width=85%>
<input type=text name=name size=15 class="input-sm">
<input type=hidden name=pno value="${no }">
</td>
</tr>
<tr>
<th class="danger text-right" width=15%>제목</th>
<td width=85%>
<input type=text name=subject size=45 class="input-sm">
</td>
</tr>
<tr>
<th class="danger text-right" width=15%>내용</th>
<td width=85%>
<textarea rows="10" cols="50" name=content></textarea>
</td>
</tr>
<tr>
<th class="danger text-right" width=15%>비밀번호</th>
<td width=85%>
<input type=password name=pwd size=10 class="input-sm">
</td>
</tr>
<tr>
<td colspan="2" class="text-center">
<input type=submit value=답변 class="btn btn-sm btn-primary">
<input type=button value=취소 class="btn btn-sm btn-primary"
onclick="javascript:history.back()"
>
</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
|
cs |
- 남이 쓴 글에 답변할 수 있는 폼
출력 화면
로그인
[새글] 누르기
글 쓰고 상세페이지 => [답변]
심청이가 답변함
끝 수고하셨습니다
반응형
'Spring' 카테고리의 다른 글
[Spring] Spring MVC CRUD게시판 만들기 (1) (0) | 2020.11.21 |
---|---|
[Spring] Cookie & Session 영화 출력 게시판 만들기 (0) | 2020.11.19 |
[Spring] Spring Transaction 답변 게시판 만들기 (1) (0) | 2020.11.19 |
[Spring] Spring AOP(스프링 AOP) 개념과 예제 (0) | 2020.11.17 |
[Spring] Spring Tiles(스프링 타일즈) 활용 - 영화 리스트 페이지 출력하기 (0) | 2020.11.16 |