1 분 소요

공지사항 수정

순서

1.Mapper처리및 테스트

2.Service 처리 및 테스트

3.Controller 처리

4.뷰처리

1.Mapper처리및 테스트

  • NoticeMapper.java

	//수정

	public int Noticeupdate(NoticeVO vo);

  • NoticeMapper.xml

	<!--수정페이지 -->
	<update id="Noticeupdate" >
	
		update anotice set ntitle = #{ntitle}, nwriter_id= #{nwriter_id}, ncontent= #{ncontent}, updateDate = sysdate where nno= #{nno} 

	</update>


mapper테스트


// 수정 테스트



	public void updateTest(){
	
	NoticeVO vo = new NoticeVO();
	
	/* vo.setNno(1); */
	vo.setNwriter_id("안녕하세요");
	vo.setNcontent("수정이랍니다");
	vo.setNtitle("수정입니다");	
	vo.setNfiles("누구세요");
	
	
	
	mapper.Noticeupdate(vo);
	
	

2.Service 처리 및 테스트

  • NoticeService.java
	//수정하기
	
	public int Noticeupdate(NoticeVO vo);

  • NoticeServiceImpl.java

	// 수정
	
	@Override
	public int Noticeupdate(NoticeVO vo) {
		
		System.out.println("수정 service입니다");
		
	
		return noticemapper.Noticeupdate(vo);
	}
	

Service 테스트

  • NoticeTest.java

public void updateTest(){
	
	NoticeVO vo = new NoticeVO();
	
	/* vo.setNno(1); */
	vo.setNwriter_id("안녕하세요");
	vo.setNcontent("수정이랍니다");
	vo.setNtitle("수정입니다");	
	vo.setNfiles("누구세요");
	
	
	
	service.Noticeupdate(vo);


3.Controller 처리

  • NoticeCotroller.java
// 수정 페이지 이동

	@RequestMapping(value = "/notice-update", method = RequestMethod.GET)
	public String NoticeUpdateGet(@RequestParam(value = "nno", required = false, defaultValue = "1") int nno,
			Model model) {

		/* NoticeVO list = noticeservice.Noticedetail(nno); */
		model.addAttribute("list", noticeservice.Noticedetail(nno));

		System.out.println("model" + model);
		System.out.println("수정 이동");

		return "admin/notice/notice-update";

	}

	// 수정 메소드

	@RequestMapping(value = "/notice-update", method = RequestMethod.POST)
	public String NoticeUpdatePost(NoticeVO list, Model model, RedirectAttributes rttr) {

		noticeservice.Noticeupdate(list);

		rttr.addFlashAttribute("result", "update success");

		System.out.println("수정메소드");
		System.out.println("list" + list);

		return "redirect:/notice-list";
	}


수정 페이지로 이동 할 수 있게 url 매핑을 하고 수정 페이지에서 수정 메소드가 호출 될 수 있도록 한다.

4.뷰 처리

  • Noticeupdate.jsp

<main class="admin-input board container w-75 p-5">
	<h4 class="text-center mb-3">공지사항 수정</h4>
	<form id="updateForm" class="input-form" style="border:none"
		action="<c:url value='notice-update?nno=${list.nno}'/>" method="post">
		<table class="table">
			<tbody>
				<tr>
					<td colspan="12">
						<div class="content">
							<span class="m-2 fw-bold">번호</span> 
							<input class="w-20" value="${list.nno}" style="border:none; margin-left:20px" readonly/>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="12">
						<div class="content d-flex">
							<span class="m-2 fw-bold">제목</span>
							<input class="w-20"
								type="text" name="ntitle" value="${list.ntitle}" style="border:none; margin-left:20px"/>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="12">
						<div class="content d-flex">
							<span class="m-2 fw-bold">작성자</span> <input class="w-20"
								type="text" name="nwriter_id" value="${list.nwriter_id}"
								readonly="readonly" style="border:none; margin-left:10px"/>
						</div>
					</td>
				</tr>

				<tr>
					<td colspan="12"><textarea class="w-100" rows="20"
							name="ncontent" id="notice_textarea" style="border: none; padding:10px">${list.ncontent}</textarea>
					</td>
				</tr>
				<!-- <script>
					CKEDITOR.replace('notice_textarea');
					 CKEDITOR.editorConfig = function(config){
		                  config.enterMode = CKEDITOR.ENTER_BR;
		               };
				</script>
 -->
			</tbody>
		</table>

		<div class="text-center ">
			<div class="text-center inputdiv">
			<input type="submit" class="btn ok" onClick="alert('수정하시겠습니까?')"value="수정"/>
				 <input class="btn reset" type="reset" value="취소"/> 
				<a href="notice-list" class="btn golist">목록</a>
				</div>
		</div>
	</form>
	<form id="infoForm" action="/notice-update" method="get">
		<input type="hidden" id="nno" value='<c:out value="${list.nno}"/>'>
	</form>
</main>





<%@ include file="../inc/footer.jsp"%>

form에 데이터를 담아 전송한다.

controller에서 model에 담은 객체를 뷰에게 el 태그를 사용한다.

댓글남기기