JSP - Maven - Message ( Del Mes)

화이티 ·2023년 12월 21일
0

JSP

목록 보기
7/12

Message DAO

public int delMessage(int num) {
			 SqlSession sqlSession = sqlSessionFactory.openSession(true);
			int cnt = 0;
			try {
				cnt = sqlSession.delete("com.smhrd.database.MessageMapper.delMessage",num);
			}catch (Exception e) {
				e.printStackTrace();
			}finally {
				sqlSession.close();
			}
			
			return cnt;
			
		}
	public int delAllMessage(String email) {
			 SqlSession sqlSession = sqlSessionFactory.openSession(true);
				int cnt = 0;
				
					cnt = sqlSession.delete("com.smhrd.database.MessageMapper.delAllMessage",email);
				
					sqlSession.close();
				
				
				return cnt;

Del Each Message

int num = Integer.parseInt(request.getParameter("num"));

		int cnt = new MessageDAO().delMessage(num);

		if (cnt > 0) {

			System.out.println("삭제 성공");

		}
		System.out.println("삭제 실패..");
		response.sendRedirect("Main.jsp");

	}

Del All Message

String email = request.getParameter("email");
		
		int cnt = new MessageDAO().delAllMessage(email);

		if (cnt > 0) {

			System.out.println("삭제 성공");

		}
		System.out.println("삭제 실패..");
		response.sendRedirect("Main.jsp");
}

Main

<!-- Q13. table형태로 나한테 온 메시지만 가져와서 보여주기
											 번호, 보낸사람, 내용, 시간 -->

				<!--  message조회하기 receipient = login email-->
				<c:if test="${loginMember!= null }">
					<c:set var="messages"
						value="${MessageDAO.allMessage(loginMember.email) }">

					</c:set>

				</c:if>

				<table>
					<tr>
						<th>번호</th>
						<th>보낸는 사람 🌴🌵</th>
						<th>내용 🍓🍓</th>
						<th>시간 🍁🍁</th>
					</tr>
					<c:forEach var="m" items="${messages }" varStatus="s">
						<tr>
							<td>${s.count}</td>
							<td>${m.sender}</td>
							<td>${m.message}</td>
							<td>${m.m_date}</td>
							<td><a href = "DelMessageService?recipient=${m.num}">삭제</a></td>
						</tr>
<c:choose>
						<c:when test=*"*${loginMember==null}*"*>
							<li>로그인을 하세요.</li>
						</c:when>
						<c:otherwise>
							<li>${loginMember.email}님에게온 메시지~ 🌼🌼</li>
							<li><a href=*"DelMessageAllService?email=*${loginMember.email }*"* class=*"button next scrolly"*>전체삭제하기</a></li>
						</c:otherwise>
					</c:choose>

MessageMapper

<delete id = "delMessage" parameterType ="int">
delete from web_message where num= #{num}
</delete>
<delete id = "delAllMessage" parameterType = "String" >
delete from web_message where recipient =#{email}
</delete>
```Message DAO

```java
public int delMessage(int num) {
			 SqlSession sqlSession = sqlSessionFactory.openSession(true);
			int cnt = 0;
			try {
				cnt = sqlSession.delete("com.smhrd.database.MessageMapper.delMessage",num);
			}catch (Exception e) {
				e.printStackTrace();
			}finally {
				sqlSession.close();
			}
			
			return cnt;
			
		}
	public int delAllMessage(String email) {
			 SqlSession sqlSession = sqlSessionFactory.openSession(true);
				int cnt = 0;
				
					cnt = sqlSession.delete("com.smhrd.database.MessageMapper.delAllMessage",email);
				
					sqlSession.close();
				
				
				return cnt;

Del Each Message

int num = Integer.parseInt(request.getParameter("num"));

		int cnt = new MessageDAO().delMessage(num);

		if (cnt > 0) {

			System.out.println("삭제 성공");

		}
		System.out.println("삭제 실패..");
		response.sendRedirect("Main.jsp");

	}

Del All Message

String email = request.getParameter("email");
		
		int cnt = new MessageDAO().delAllMessage(email);

		if (cnt > 0) {

			System.out.println("삭제 성공");

		}
		System.out.println("삭제 실패..");
		response.sendRedirect("Main.jsp");
}

Main

<!-- Q13. table형태로 나한테 온 메시지만 가져와서 보여주기
											 번호, 보낸사람, 내용, 시간 -->

				<!--  message조회하기 receipient = login email-->
				<c:if test="${loginMember!= null }">
					<c:set var="messages"
						value="${MessageDAO.allMessage(loginMember.email) }">

					</c:set>

				</c:if>

				<table>
					<tr>
						<th>번호</th>
						<th>보낸는 사람 🌴🌵</th>
						<th>내용 🍓🍓</th>
						<th>시간 🍁🍁</th>
					</tr>
					<c:forEach var="m" items="${messages }" varStatus="s">
						<tr>
							<td>${s.count}</td>
							<td>${m.sender}</td>
							<td>${m.message}</td>
							<td>${m.m_date}</td>
							<td><a href = "DelMessageService?recipient=${m.num}">삭제</a></td>
						</tr>
<c:choose>
						<c:when test=*"*${loginMember==null}*"*>
							<li>로그인을 하세요.</li>
						</c:when>
						<c:otherwise>
							<li>${loginMember.email}님에게온 메시지~ 🌼🌼</li>
							<li><a href=*"DelMessageAllService?email=*${loginMember.email }*"* class=*"button next scrolly"*>전체삭제하기</a></li>
						</c:otherwise>
					</c:choose>

MessageMapper

<delete id = "delMessage" parameterType ="int">
delete from web_message where num= #{num}
</delete>
<delete id = "delAllMessage" parameterType = "String" >
delete from web_message where recipient =#{email}
</delete>
profile
열심히 공부합시다! The best is yet to come! 💜

0개의 댓글