wasup
Spring Legacy MiNi Project - STS / board view 본문
반응형
1. 툴 다운로드
sts : ( https://spring.io/tools )
2. 미니 프로젝트
2-1. Spring Legacy MiNi Project
2-2. Spring Boot MiNi Project
2-3 eGov
Spring Legacy MiNi Project 게시판, 회원관리
개발환경
- window10
- tomcat8.5
- mysql 5.5
- java version 1.8.0_40
- sts3
- jdbc 3.2.3
- myBatis 3.2.8
개발언어
- java, spring, jsp
- jsjq
- html5, css3
글쓰기화면 : writeForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>writeForm</title>
<script src="//code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
function check(){
if($('#writer').val()==''){
alert("이름을 입력하세요.");
$('#writer').focus();
return false;
}
if($('#subject').val()==''){
alert("제목을 입력하세요.");
$('#subject').focus();
return false;
}
if($('#content').val()==''){
alert("내용을 입력하세요.");
$('#content').focus();
return false;
}
if($('#pw').val()==''){
alert("비밀번호를 입력하세요.");
$('#pw').focus();
return false;
}
return true
}
</script>
<style src="/css/common.css"></style>
</head>
<body>
<c:if test="${num==0}"><!-- 글번호가 없으면 첫 번째 글이므로 일반 글쓰기 -->
<h2>게시판 글쓰기</h2>
</c:if>
<c:if test="${num!=0}"><!-- 글번호가 있으면 첫 번째 글이 아니므로 답글쓰기 -->
<h2>답글쓰기</h2>
</c:if>
<form method="post" action="writePro" onSubmit="return check()">
<input type="hidden" name="pageNum" value="${pageNum}">
<input type="hidden" name="num" value="${num}">
<input type="hidden" name="ref" value="${ref}">
<input type="hidden" name="re_step" value="${re_step}">
<input type="hidden" name="re_level" value="${re_level}">
<table>
<tr>
<td>이름</td>
<td><input type="text" name="writer" id="writer" size="30"/></td>
</tr>
<tr>
<td>글 제목</td>
<td>
<!-- 원글 -->
<c:if test="${num==0}">
<input type="text" name="subject" id="subject" size="40"/>
</c:if>
<!-- 답글 -->
<c:if test="${num!=0}">
<input type="text" name="subject" id="subject" size="40" value="[답변]"/>
</c:if>
</td>
</tr>
<tr>
<td>글 내용</td>
<td><textarea name="content" id="content" rows="10" cols="60"></textarea></td>
</tr>
<tr>
<td>비밀번호</td>
<td><input type="password" name="pw" id="pw" size="20"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<!-- 원글쓰기 -->
<c:if test="${num==0}">
<input type="submit" value="글쓰기"/>
</c:if>
<!-- 답글쓰기 -->
<c:if test="${num!=0}">
<input type="submit" value="답글쓰기"/>
</c:if>
<input type="reset" value="다시쓰기"/>
<input type="button" value="글목록" onClick="location.href='list'"/>
</td>
</tr>
</table>
</form>
</body>
</html>
cmd : 확인해보기
mysql> select * from board
-> ;
+-----+----------+------------+------+---------------------+-----------+-----+---------+----------+----------+-----------------+
| num | writer | subject | pw | regdate | readcount | ref | re_step | re_level | content | ip |
+-----+----------+------------+------+---------------------+-----------+-----+---------+----------+----------+-----------------+
| 1 | 손목아파 | 집가고싶다 | qqq | 2021-08-02 15:01:48 | 4 | 1 | 0 | 0 | 피곤해 | 0:0:0:0:0:0:0:1 |
| 2 | ABC | 초콜릿 | qqq | 2021-08-02 15:02:03 | 1 | 2 | 0 | 0 | 먹고싶다 | 0:0:0:0:0:0:0:1 |
| 3 | 오늘은 | 비온다 | qqq | 2021-08-02 15:02:23 | 2 | 3 | 0 | 0 | 꿉꿉하다 | 0:0:0:0:0:0:0:1 |
| 4 | sdf | sdf | 1111 | 2021-08-09 17:40:17 | 0 | 4 | 0 | 0 | sdf | 0:0:0:0:0:0:0:1 |
| 5 | qwe | qwe | qwe | 2021-08-09 17:43:36 | 0 | 5 | 0 | 0 | qwe | 0:0:0:0:0:0:0:1 |
+-----+----------+------------+------+---------------------+-----------+-----+---------+----------+----------+-----------------+
5 rows in set (0.00 sec)
mysql>
리스트 화면 : list.jsp
<%@ 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"%>
<%-- <jsp:include page="../inc/head.jsp"/> --%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>list</title>
</head>
<body>
<h2>글목록(전체)</h2>
<table width="80%">
<tr>
<td align="right">
<a href="writeForm">글쓰기</a>
</td>
</tr>
</table>
<!-- 글이 있으면 -->
<c:if test="${count!=0}">
<table width="80%">
<tr>
<td>글번호</td>
<td>제목</td>
<td>글쓴이</td>
<td>작성일</td>
<td>조회수</td>
<td>ip</td>
</tr>
<c:forEach var="dto" items="${list}">
<tr>
<td>
<!-- dto.num 수정할것 -->
<c:out value="${number}"/>
<c:set var="number" value="${number-1}"/>
<!-- 역순을 위해 -1을 해줬는데 왜 역순으로 해야하는지 모르겠음. -->
</td>
<!-- 글제목 -->
<td>
<!-- 답글이면 -->
<!-- 답글이면 이미지 넣는 방법 webapp/resources/imgs-->
<c:if test="${dto.re_level>0}"><!-- re_level이 0보다 크면 -->
<img src="resources/imgs/level.gif" width="${5*dto.re_level}" height="16" class="ico_level"/><!-- 레벨만큼 들어가게 -->
<img src="resources/imgs/re.gif" class="ico_re"/><!-- 답글표시 이미지 -->
</c:if>
<!-- 원글이면 -->
<c:if test="${dto.re_level==0}">
<img src="resources/imgs/level.gif" width="${5*dto.re_level}" height="16" class="ico_level"/>
</c:if>
<!-- 글제목을 클릭하면 글내용보기로 이동 -->
<a href="content?num=${dto.num}&pageNum=${pageNum}" title="${dto.subject}">${dto.subject}</a>
<!-- 조회수가 20회 이상이면 hot.gif표시 -->
<c:if test="${dto.readcount>=20}">
<img src="resources/imgs/hot.gif" class="ico_hot"/>
</c:if>
</td>
<td>${dto.writer}</td>
<td><fmt:formatDate value="${dto.regdate}" pattern="yyyy-MM-dd hh:mm:ss"/></td>
<td>${dto.readcount}</td>
<td>${dto.ip}</td>
</tr>
</c:forEach>
</table>
</c:if>
<!-- 글이 없으면 -->
<c:if test="${count==0}">
저장된 글이 없습니다.
</c:if>
<!-- 블럭, 페이징 처리 -->
<table width="80%">
<tr>
<td align="center">
<!-- 에러 방지 -->
<!-- 페이지수가 10,20,30보다 크면? -->
<c:if test="${endPage>pageCount}">
<c:set var="endPage" value="#{pageCount}"/>
</c:if>
<!-- 이전 블럭 -->
<c:if test="${startPage>10}">
<a href="list?pageNum=${startPage-10}">이전블럭</a>
</c:if>
<!-- 페이지처리 -->
<c:forEach var="i" begin="${startPage}" end="${endPage}">
<a href="list?pageNum=${i}">[${i}]</a>
</c:forEach>
<!-- 다음 블럭 -->
<c:if test="${endPage<pageCount}">
<a href="list?pageNum=${startPage+10}">다음블럭</a>
</c:if>
</td>
</tr>
</table>
</body>
</html>
글상세화면 : content.jsp
<%@ 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>content</title>
</head>
<body>
<h2>글내용 보기</h2>
<table>
<tr>
<td>글번호</td>
<td>${bdto.num}</td>
<td>조회수</td>
<td>${bdto.readcount}</td>
</tr>
<tr>
<td>이름</td>
<td>${bdto.writer}</td>
<td>작성일</td>
<td><fmt:formatDate value="${bdto.regdate}" pattern="yyyy-MM-dd"/></td>
</tr>
<tr>
<td>글제목</td>
<td colspan="3">${bdto.subject}</td>
</tr>
<tr>
<td>내용</td>
<td colspan="3"><pre>${bdto.content}</pre></td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="button" value="글수정" onClick="location.href='updateForm?num=${num}&pageNum=${pageNum}'"/>
<input type="button" value="글삭제" onClick="location.href='delete?num=${num}&pageNum=${pageNum}'"/>
<input type="button" value="새글쓰기" onClick="location.href='writeForm'"/>
<input type="button" value="답글쓰기" onClick="location.href='writeForm?num=${num}&pageNum=${pageNum}&ref=${bdto.ref}&re_step=${bdto.re_step}&re_level=${bdto.re_level}'"/>
<input type="button" value="글목록" onClick="location.href='list?pageNum=${pageNum}'"/>
</td>
</tr>
</table>
</body>
</html>
글 수정 화면 : updateForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>updateForm</title>
<h2>글 수정 폼</h2>
<form method="post" action="updatePro">
<table>
<tr>
<td>이름</td>
<td>
<input type="text" name="writer" value="${bdto.writer}"/>
<input type="hidden" name="num" value="${bdto.num}"/>
</td>
</tr>
<tr>
<td>글제목</td>
<td>
<input type="text" name="subject" value="${bdto.subject}" size="40"/>
</td>
</tr>
<tr>
<td>글내용</td>
<td>
<textarea name="content" rows="10" cols="60">${bdto.content}</textarea>
</td>
</tr>
<tr>
<td>암호</td>
<td><input type="password" name="pw" size="10"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="글수정"/>
<input type="reset" value="다시쓰기"/>
<input type="button" value="글 목록" onclick="location.href='list?pageNum=${pageNum}'"/>
</td>
</tr>
</table>
</form>
</body>
</html>
반응형
'IT > Java' 카테고리의 다른 글
Spring Legacy MiNi Project - STS / tiles 적용 (0) | 2021.08.15 |
---|---|
Spring) Tiles 사용해보기 (0) | 2021.08.13 |
Spring Legacy MiNi Project - STS / board java (0) | 2021.08.10 |
Spring) AOP( Aspect Oriented Programming ) / 관점지향 프로그래밍 (0) | 2021.08.09 |
Spring Legacy MiNi Project - STS / member view (0) | 2021.08.09 |
Comments