작성
·
303
0
답변 4
0
0
어찌하다보니까. 아래처럼 하니까 되네요. 어렵다. 소뒷발로 쥐잡음
@PostMapping(value = "/books/Search_id1")
public String searchIdFormList(BookMemberForm form,Model model) {
BookMember bookMemberUi = new BookMember();
Optional<BookMember> bookMember = bookMagService.findOne(form.getBookId());
bookMemberUi = bookMember.get();
model.addAttribute("member", bookMemberUi);
return "bookMember/bookMemberSingle";
}
0
친절한 답변 감사합니다. 근데 계속해서 질문하게되네요. 미천한 공부라...ㅠ.ㅠ
@PostMapping(value = "/books/Search_id1")
public String searchIdFormList(BookMemberForm form,Model model) {
System.out.println("#### BookMagController @PostMapping ===> bookId: " + form.getBookId());
model.addAttribute("members", bookMagService.findOne(form.getBookId()));
System.out.println("]]]]]] #### BookMagController bookMagService model : " + model);
return "bookMember/bookMemberSingle";
}
public Optional<BookMember> findOne(Long memberId) {
System.out.println("#### BookMagService ===> bookId: " + memberId);
return bookMemberRepository.findByBookId(memberId);
}
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<div>
<table>
<thead>
<tr>
<th>도서ID</th>
<th> 도서명 </th>
<th> 도서십진분류 </th>
<th> 사업자등록번호 </th>
<th> 출판사 </th>
<th> 저자id </th>
<th> 저자명 </th>
<th> 출판일 </th>
<th> 가격 </th>
</tr>
</thead>
<tbody>
<tr th:each="member : ${members}">
<td th:text="${member.bookId}"></td>
<td th:text="${member.bookName}"></td>
<td th:text="${member.book_kdc}"></td>
<td th:text="${member.book_publisher_business_no}"></td>
<td th:text="${member.book_publisher}"></td>
<td th:text="${member.book_author_id}"></td>
<td th:text="${member.book_author}"></td>
<td th:text="${member.book_make_date}"></td>
<td th:text="${member.book_price}"></td>
</tr>
</tbody>
</table>
</div>
</div> <!-- /container -->
</body>
</html>
#### BookMagController @PostMapping ===> bookId: 1001
#### BookMagService ===> bookId: 1001
Hibernate: select bookmember0_.book_id as book_id1_0_, bookmember0_.book_name as book_nam2_0_,
bookmember0_.book_author as book_aut3_0_, bookmember0_.book_author_id as book_aut4_0_,
bookmember0_.book_kdc as book_kdc5_0_, bookmember0_.book_make_date as book_mak6_0_,
bookmember0_.book_price as book_pri7_0_, bookmember0_.book_publisher as book_pub8_0_,
bookmember0_.book_publisher_business_no as book_pub9_0_ from book_mag bookmember0_
where bookmember0_.book_id=?
]]]]]] #### BookMagController bookMagService model : {bookMemberForm=book.booksmag.controller.BookMemberForm@52983985,
org.springframework.validation.BindingResult.bookMemberForm=
org.springframework.validation.BeanPropertyBindingResult: 0 errors,
members=Optional[book.booksmag.domain.BookMember@3b5ecc69]}
2022-06-30 10:57:56.885 ERROR 32896 --- [nio-8080-exec-4] org.thymeleaf.TemplateEngine :
[THYMELEAF][http-nio-8080-exec-4] Exception processing template "bookMember/bookMemberSingle":
Exception evaluating SpringEL expression: "member.bookId" (template: "bookMember/bookMemberSingle" - line 22, col 21)
org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "member.bookId" (template: "bookMember/bookMemberSingle" - line 22, col 21)
rg.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'bookId' cannot be found on object of type 'java.util.Optional'
- maybe not public or not valid?
0
public String searchIdFormlist(BookMemberForm form,Model model) {
BookMember bookMember = new BookMember();
bookMagService.findOne(bookMember.getBook_id());
==
findOn으로 하나의 회원을 받는다고 한다면,
BookMemberForm에서 해당 회원의 Id가 포함되어 있지 않을까요?
bookMagService.findOne(bookMember.getBook_id());
바로 윗 라인에서 생성한 인스턴스에서 id를 가져오는게 아닌,
BookMemberForm form
파라미터로 받아서 처리해야 될 것 같네요
bookMagService.findOne(form.getBook_id())
이후 코드는
bookService에서 찾아온 회원을 받아서 모델로 넘기면 될 거같구요.
특정 회원 한명의 데이터니 s는 빼면 될거같네요.
결과적으로 3줄자리 코드를 위와 같이 한줄로 작성해도 됩니다.
@GetMapping(value = "/books/Search_id")
public String searchIdForm() {
return "bookMember/searchIdBookMemberForm";
}
@@@ searchIdBookMemberForm.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<h2> 도서 ID 조회 </h2>
<form action="/books/Search_id1" method="post">
<div class="form-group">
<label for="book_id">도서ID:</label>
<input type="text" id="book_id" name="book_id" maxlength="13" placeholder="도서ID를 입력하세요">
</div>
<button type="submit">도서ID조회</button>
</form>
</div> <!-- /container -->
</body>
</html>
@PostMapping(value = "/books/Search_id1")
public String searchIdFormlist(BookMemberForm form,Model model) {
BookMember bookMember = new BookMember();
bookMagService.findOne(bookMember.getBook_id());
===> 이곳에서 값을 어떻게 받아서 화면에 전달 하나요?
model.addAttribute("members", bookMember);
return "bookMember/bookMemberSingle";
}
@@@@ bookMemberSingle.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<div>
<table>
<thead>
<tr>
<th>도서ID</th>
<th> 도서명 </th>
<th> 도서십진분류 </th>
<th> 사업자등록번호 </th>
<th> 출판사 </th>
<th> 저자id </th>
<th> 저자명 </th>
<th> 출판일 </th>
<th> 가격 </th>
</tr>
</thead>
<tbody>
<tr th:text="member : ${members}">
<td th:text="${member.book_id}"></td>
<td th:text="${member.bookName}"></td>
<td th:text="${member.book_kdc}"></td>
<td th:text="${member.book_publisher_business_no}"></td>
<td th:text="${member.book_publisher}"></td>
<td th:text="${member.book_author_id}"></td>
<td th:text="${member.book_author}"></td>
<td th:text="${member.book_make_date}"></td>
<td th:text="${member.book_price}"></td>
</tr>
</tbody>
</table>
</div>
</div> <!-- /container -->
</body>
</html>