Framework 82

[Error] 아이디 중복 체크

ajax로 아이디 값을 입력받을 때마다 서버에 전송해서 boolean 값을 받는다. boolean existsByUsername(String id); 를 이용해서 데이터베이스에서 아이디 중복 체크를 했다. 문제점 서버에서 넘긴 flag는 boolean이다. 프런트단에서 출력하니까 엉뚱하게 회원가입 html 소스 코드가 나타난다. '/user/idCheck'으로 가야하는데 안 가는 것 같다. 로그가 안 찍힌다. ✨ 해결 원인은 스프링시큐리티였다. 홈과 회원가입 페이지만 접근을 허용해서 '/user/idCheck'가 차단된 것이다. post 방식으로 요청한 '/user/idCheck'에 가지 않고, '/user/joinForm'에 가서 return 값이 회원가입 html 소스 코드다. 로그인 안 해도 접근할..

Spring Security 사용자 id 가져오기

Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); String username = ((UserDetails)principal).getUsername(); 작성한 글을 저장할 때 작성자를 로그인 한 id로 해주었다. 위의 코드를 추가하면 로그인 한 유저의 id를 가져올 수 있다. 참고 👉 https://dzone.com/articles/how-to-get-current-logged-in-username-in-spring-se Spring Security: Access Current Logged-In Username - DZone Security This tutorial demonstrates ho..

[ERROR] EL1004E: Method call: Method hasError(java.lang.String) cannot be found on type org.thymeleaf.spring5.expression.Fields

🦔 에러 로그 Exception evaluating SpringEL expression: "#fields.hasError('content')" (template: "post/detail" - line 49, col 27) EL1004E: Method call: Method hasError(java.lang.String) cannot be found on type org.thymeleaf.spring5.expression.Fields s를 빼먹어서 생긴 에러였다 ㅠㅠ "#fields.hasErrors('content')"가 맞다.

Spring Security 기본 로그인 화면 제거

Spring Security를 사용하면 처음에 로그인 화면이 뜬다. 내가 원하는 url을 쳐도 안 넘어간다.. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity httpSecurity) throws Exception{ httpSecurity.httpBasic().disable(); } } import 부분은 제외하고 가져왔다. 이렇게 하니 사라졌다!! 이 방법 말고 아래의 방법을 쓰자. ✨ URL에 따라 인증된 사용자만 접근하도록 하기 @Override protected void config..

[Error] Error creating bean with name 'thymeleafViewResolver' defined in class path resource

springsecurity를 사용하기 위해 build.gradle에 의존성 추가 후 아래와 같은 에러가 떴다. 에러 로그가 워낙 길어서 필요한 부분만 가져왔다. Error creating bean with name 'thymeleafViewResolver' defined in class path resource Error creating bean with name 'templateEngine' defined in class path resource Failed to instantiate [org.thymeleaf.spring5.SpringTemplateEngine]: Factory method 'templateEngine' threw exception; Error creating bean with nam..

[Error] spelevaluationexception

EL1008E: Property or field 'name' cannot be found on object of type 'Bulletin.Board.domain.posts.User' - maybe not public or not valid? 에러가 발생한 일부 소스 코드 name부터 에러가 생기니 밑에 속성들도 안 된다. User Entity에서 getter가 없어서 생긴 에러 모든 멤버변수의 getter를 추가한 후 해결:) 덕분에 Thymeleaf가 어떻게 동작하는지 알았다. 에러는 Thymeleaf에서 생겼지만, Entity 쪽에서 해결해서 카테고리 분류를 Spring으로 했다. 참고 👇 https://stackoverflow.com/questions/57369016/el1008e-property..

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..