글수정 페이지

글 수정하는 페이지도 있어야함

JOIN문으로 만든 쿼리를 가지고 findById 메소드를 이용해서 DTO를 가지고 뿌려도 되지만 나는 update.jsp에 필요한 요소만을 가지고 만듬

이때 주의해야할 것은 id, title, content로 id도 필요하다.

<!-- 나의 문제점. update할 때 단순히 title, content만 넣으면 안됨 id도 포함해야한다 -->
  <select id="findByIdInUpdate" resultType="com.cos.springblog.model.Post">
 	SELECT id, title, content, userId, createDate
 	FROM post
 	WHERE id = #{id}
  </select>
@GetMapping("/update/{id}")
  // update 뒤에 글번호 붙이는 게 꼭 필요한지는 모르겠다. 있는게 나은 듯.
	public String updatePage(@PathVariable int id, Model model) {
		
		//이렇게 하면 안된다 boardDto에 id가없음
		//Post post = postRepository.findTitleAndContent(id);
		
		Post post = postRepository.findByIdInUpdate(id);
		
		model.addAttribute("boardDto", post);
		return "board/update";
	}

update.jsp

<form action="/updateProc" method="POST">
		<input type = "hidden" value ="${boardDto.id}" name ="id"/>
		
		<div class="form-group">
			<label for="title">Title:</label>
			<input value="${boardDto.title}" type="text" class="form-control" placeholder="title" id="title" name="title">
		</div>
	
		<div class="form-group">
			<label for="content">Content:</label>
			<textarea id="summernote" class="form-control" rows="5" id="content" name="content">
				${boardDto.content}
			</textarea>
		</div>
						
			<!-- </div> 네임이 없으면 전송을 못한다 .text() , val, html -->
		<button type="submit" class="btn btn-primary">수정하기</button>		
	</form>

글 수정

글 수정페이지에는 이전에 썼던 글을 보여주는 기능과 submit을 하면 title과 content를 가지고 update하는 기능이 있다.

-Builder가 필요한 경우와 필요없는 경우..???

DetailResponseDto detailDto = DetailResponseDto.builder()
				.boardDto(boardDto)
				.replyDtos(replyDtos)
				.build();
Post postRequest = Post.builder()
				
				.userId(principal.getId())
				.title(post.getTitle())
				.content(post.getContent())
				.build();