글 수정 하기1

JEONG SUJIN·2022년 12월 30일
0

BoardService.java

입력된 modifyContentBean의 인덱스번호로 검색해 다른 정보들을 입력한다.

//글 인덱스번호로 검색해서 글 정보를 modifyContentBean 입력한다.
	public void getContents(ContentBean modifyContentBean) {
		
		ContentBean temp = boardMapper.getContentInfo(modifyContentBean.getContent_idx());
		
		modifyContentBean.setContent_writer_name(temp.getContent_writer_name());
		modifyContentBean.setContent_date(temp.getContent_date());
		modifyContentBean.setContent_subject(temp.getContent_subject());
		modifyContentBean.setContent_text(temp.getContent_text());
		modifyContentBean.setContent_file(temp.getContent_file());
	
	}

BoardController.java

파라미터로 board_idx, content_idx 받아서 modifyContentBean 객체에 추가해서 model에 추가하기

@GetMapping("modify")
	public String modify(@RequestParam("board_info_idx") int board_info_idx,
						@RequestParam("content_idx") int contet_idx, Model model,
						@ModelAttribute("modifyContentBean") ContentBean modifyContentBean) {
		
		modifyContentBean.setContent_board_idx(board_info_idx);
		modifyContentBean.setContent_idx(contet_idx);
		
		boardService.getContents(modifyContentBean);
		model.addAttribute("modifyContentBean", modifyContentBean);
		return "board/modify";
	}
	

modify.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="form" uri="http://www.springframework.org/tags/form" %>

<c:set var='root' value="${pageContext.request.contextPath }/"/>


<!-- 상단 메뉴 부분 -->
<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:form action="${root }board/modify_pro" modelAttribute="modifyContentBean" enctype="multipart/form-data">
                <form:hidden path="content_idx"/>
                <form:hidden path="content_board_idx"/>
                
                <div class="form-group">
                 <form:label path="content_writer_name">작성자</form:label>
                  <form:input path="content_writer_name" class="form-control" readonly="true" />
                </div>
                
                <div class="form-group">
                 <form:label path="content_date">작성날짜</form:label>
                  <form:input path="content_date" class="form-control" readonly="true" />
                </div>
                
                
                
                <div class="form-group">
                  <form:label path="content_subject">제목</form:label>
                  <form:input path="content_subject" class="form-control" />
                  <form:errors path="content_subject" style="color:red" />
                </div>
                
                <div class="form-group">
                  <form:label path="content_text">내용</form:label>
                  <form:textarea path="content_text" class="form-control" rows="10" style="resize: none"/>
                  <form:errors path="content_text" style="color:red" />      
                </div>
                
                <div class="form-group">
                  <form:label path="content_file">첨부 이미지</form:label>
                  <c:if test="${modifyContentBean.content_file != null }">
                   <img src="${root }upload/${modifyContentBean.content_file}" width="100%" />
                  <form:hidden path="content_file"/>
                  </c:if>
                  
                  <form:input type="file" path="upload_file" class="form-control" accept="image/*" />
                </div>
                
                <div class="form-group">
                  <div class="text-right">
                    <form:button class='btn btn-primary'>작성하기</form:button>
                    <a href="${root }board/read?board_info_idx=${modifyContentBean.content_board_idx}&content_idx=${modifyContentBean.content_idx}" class="btn btn-info">취소 </a>
                  </div>
                </div>
                
              </form:form>
              
              
              
            </div>
          </div>
        </div>
        <div class="col-sm-3"></div>
      </div>
    </div>

<!-- 하단 푸터부분 -->
<c:import url="/WEB-INF/views/include/footer.jsp" />

글 수정 페이지

profile
기록하기

0개의 댓글