소개
게시글
질문&답변
2022.06.30
findOne
어째건 감사합니다.
- 0
- 4
- 293
질문&답변
2022.06.30
findOne
어찌하다보니까. 아래처럼 하니까 되네요. 어렵다. 소뒷발로 쥐잡음 @PostMapping(value = "/books/Search_id1")public String searchIdFormList(BookMemberForm form,Model model) { BookMember bookMemberUi = new BookMember(); Optional bookMember = bookMagService.findOne(form.getBookId()); bookMemberUi = bookMember.get(); model.addAttribute("member", bookMemberUi); return "bookMember/bookMemberSingle";}
- 0
- 4
- 293
질문&답변
2022.06.30
findOne
친절한 답변 감사합니다. 근데 계속해서 질문하게되네요. 미천한 공부라...ㅠ.ㅠ [[[[[ BookMagController ]]]]] @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"; } [[[[ BookMagService.java ]]]]]] public Optional findOne(Long memberId) { System.out.println("#### BookMagService ===> bookId: " + memberId); return bookMemberRepository.findByBookId(memberId); } [[[[[ bookMemberSingle.html ]]]]]] 도서ID 도서명 도서십진분류 사업자등록번호 출판사 저자id 저자명 출판일 가격 상기처럼했는데 아래와같은 오류가 나네요? 어떻게 해야할지 감이 안옵니다. #### 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? 타입이 안맞다는것 같은데요? cannot be found on object of type 'java.util.Optional'
- 0
- 4
- 293
질문&답변
2022.06.29
에러 문의
public class BookMember { private String bookName; Optional findByBookName(String bookName); 상기처럼 했더니 에러는 안나네요. 감사합니다. 코볼세데라 어렵네요 ㅋㅋ 개념이 안잡힘
- 0
- 10
- 408
질문&답변
2022.06.29
에러 문의
"findBy" 이후에 엔티티의 속성 이름을 붙이다. 이 속성 이름은 첫 글자는 대문자로 한다. 상기처럼 Optional findByBook_name(String book_name); 으로 바꾸고 BookMember에도 book_name인데 private String book_name; Failed to create query for method public abstract java.util.Optional book.booksmag.repository.SpringDataJpaBookMemberRepository.findByBook_name(java.lang.String)! No property 'book' found for type 'BookMember'! 왜 Book_name이 아니고 'book' 으로 인식되나요? "_"를 쓰면 안되나요? 귀찬게 해서 죄송합니다.
- 0
- 10
- 408