Framework/Spring Boot 75

Repository와 Service의 차이

왜 두 개를 구분 짓는지 이유를 알고 싶었다. Repository는 DB에 접근하는 코드를 모아두었다. Service는 DB에 직접적으로 접근하는 것은 Repository에 맡겨서 비즈니스 로직에 집중할 수 있다. 비즈니스 로직은 데이터베이스와 유저 인터페이스간의 정보 교환을 다루는 알고리즘 나는 서비스가 리포지토리를 이용해서 어떤 기능(비즈니스 로직)을 만드는 것이라고 이해했다. 참고 👇 https://www.inflearn.com/questions/77417 Repository vs Service 의 역할의 차이점 - 인프런 | 질문 & 답변 안녕하세요. 선생님 강의 정말 잘 보고있습니다. 궁금한점이 있어서요 Repository 패키지와 Service 패키지가 보통 구분되어있는데 정확하게 쓰임새의 차..

[Error] 수정 후 조회수 초기화

특정 게시글을 클릭해서 상세보기를 할때 조회수가 1씩 증가하도록 만들었다. 게시글을 수정하면 조회수가 0으로 초기화되는 문제점을 발견했다. 디버그를 해보니 수정 버튼을 누르면 작동하는 putmapping 쪽에서 조회수가 0이었다. get으로 요청을 받고, 데이터를 출력할 때까지는 조회수가 제대로 나왔는데.. 결론은 get으로 요청 받았을 때의 객체와 put으로 요청 받았을 때의 객체가 다르다. put으로 요청 받았을 때의 객체는 사용자가 수정한 데이터다.(프런트엔드단의 데이터) get으로 요청 받았을 때의 객체는 데이터베이스에서 가져온 데이터. 🍯 해결 int view=postService.findOne(id).getView(); post.setView(view); // 조회수 저장 id로 해당 객체를 ..

[Error] Can not set int field Bulletin.Board.domain.posts.Post.view to null value

Can not set int field Bulletin.Board.domain.posts.Post.view to null value 다음과 같은 에러가 떴다. int를 Integer 타입으로 바꾸고 해결 int는 null로 초기화 할 수 없다. 참고 👇 https://www.python2.net/questions-803934.htm 스프링 부트 엔터티 클래스의 오류, int 필드를 null 값으로 설정할 수 없습니다 이것은 Entity 클래스입니다 @Column(length = 4) private int stu_id; 프로젝트를 실행할 때 null 값을 추가 할 수 있기 때문에 stu_id에 값을 전달하지 않습니다. 다음 오류가 평가되었습니다. Can not set int field www.python2..

[Error] org.springframework.beans.factory.UnsatisfiedDependencyException

스프링 버전이 낮아서 2.5.2로 바꿨더니 서버 실행하면 아래 에러가 뜨면서 중단됨.. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0;nested exception is org.springfram..

[Error] "Request method 'GET' not supported"

게시글 삭제 버튼을 클릭하면 "Request method 'GET' not supported"가 떴다. @DeleteMapping을 사용하려고 했는데 이런 에러가 떴다. @GetMapping으로 바꾸면 에러가 사라지지만, @DeleteMapping을 쓰고 싶어서 방법을 찾아봤다. spring.mvc.hiddenmethod.filter.enabled=true application.properties에 추가한다. // 삭제 @DeleteMapping("/post/delete/{id}") public String delete(@PathVariable("id") Long id) { postService.deletePost(id); return "redirect:/"; } 컨트롤러 삭제 th:method="del..

[Error] Request method 'POST' not supported

DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported] 수정 기능 구현할 때 컨트롤러에서 mapping 방식을 post에서 put으로 바꿨더니 이런 에러가 생겼다. post는 생성, put은 수정할 때 쓰인다고 한다. post는 멱등성이 없어서 같은 값을 여러 번 보내면 해당 값이 수정되는 것이 아니다. 새롭게 추가되어 여러 개가 생긴다 .. 🍯 해결 spring.mvc.hiddenmethod.filter.enabled=true 이 코드를 application.properties에 추가해줌 @Bean p..

[Error] Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefF..

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBE..

[Error] javax.net.ssl.SSLException

spring.datasource.url=jdbc:mysql://localhost:3306?&useSSL=false application.properties에서 위와 같이 수정 출처: https://kikikimoong.tistory.com/entry/SpringBoot-Closing-inbound-before-receiving-peers-closenotify-예외-없애기 [SpringBoot] Closing inbound before receiving peer's close_notify 예외 없애기 ** BEGIN NESTED EXCEPTION ** javax.net.ssl.SSLException MESSAGE: closing inbound before receiving peer's close_notif..

[error] Thymeleaf Exception processing template

Exception processing template "post/createPostForm": Exception parsing document: template="post/createPostForm", line 10 - column 11 🎁 해결방법 1. input 또는 meta에서 마지막에 /를 썼는지 확인하자 참고 👉 https://stackoverflow.com/questions/48327528/thymeleaf-exception-parsing-document-in-spring Thymeleaf Exception parsing document in Spring Error message reads: There was an unexpected error (type=Internal Server Error..