[Spring boot] Spring sequrity에서 로그인된 회원 계정 가져오기

조히고닝·2023년 3월 22일
0
 <a href="javascript:void(0);" th:data-uri="@{|/question/delete/${question.id}|}"
                           class="delete btn btn-sm btn-outline-secondary" sec:authorize="isAuthenticated()"
                           th:if="${question.author != null and #authentication.getPrincipal().getUsername() == question.author.username}"
                           th:text="삭제"></a>

에서

#authentication.getPrincipal().getUsername()

이거나

  <li sec:authorize="isAuthenticated()">
               <a th:href="@{|/user/mypage/{}|}">
                   <span sec:authentication="principal.username"></span>
               </a>님 환영합니다.
           </li>
           

sec:authentication="principal.username"

둘중 한가지 방법을 선택해서 쓰면 된다.

0개의 댓글