본문 바로가기
Spring Security H2 데이터 베이스 사용시 프레임 오류 스프링 시큐리티를 사용하면 자동으로 CSRF 토큰이 생성된다. 측정 페이지 url은 스프링 시큐리티를 해제할 수 있지만, 그 상태로 H2에 접속이 불가하다. H2 콘솔은 스프링과 상관없는 일반 애플리케이션이기 때문에 예외처리를 해주어야한다. 문제화면: @Configuration @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.authorizeRequests().antMatchers("/**").permitAll() .and() .csrf().ignoringAntMatchers("/h2-console/**") ;.. 2022. 10. 27.
페이징 구현하기 JPA 환경 구축시 설치했던 JPA 관련 라이브러리에 이미 페이징을 위한 패키지가 있다. org.springframework.data.domain.Page org.springframework.data.domain.PageRequest org.springframework.data.domain.Pageable 1) 리포지터리에 findAll 메서드를 추가한다. public interface QuestionRepository extends JpaRepository { Page findAll(Pageable pageable); } 이 때 임포트가 domain.Page이어야 한다. import org.springframework.data.domain.Page; import org.springframework.da.. 2022. 10. 27.
Spring Boot Validation // null로 등록 불가능하게 하는 방법 Spring boot로 게시판이나 댓글을 구현할 때 빈 값으로 입력 못하게 하는 여러 방법은 여러가지가 있지만 form을 사용해서 입력값을 체크하는 방법이 있다. Spring Boot Validation 라이브러리 추가 dependencies { implementation 'org.springframework.boot:spring-boot-starter-validation' } Spring Boot Validation을 설치하면 아래와 같은 애너테이션을 사용할 수 있다. @Size 문자 길이를 제한한다. @NotNull Null을 허용하지 않는다. @NotEmpty Null 또는 빈 문자열("")을 허용하지 않는다. @Past 과거 날짜만 가능 @Future 미래 날짜만 가능 @FutureOrPresen.. 2022. 10. 27.
MAC m1 H2 Databases 설치 방법 https://www.h2database.com/html/download.html Downloads Downloads Version 2.1.214 (2022-06-13) Windows Installer (SHA1 checksum: 5f7cd83d394df5882ed01553935463a848979f29) Platform-Independent Zip (SHA1 checksum: 5ff027217098bf6c800ef96b98f3a381b320e53d) Version 2.1.212 (2022-04-09) Windows Installer (SHA1 check www.h2database.com 위 다운로드 링크로 접속한다. 내 경우는 2.1.212 버전을 설치했다. (최신꺼는 믿을 수 가 없어요..ㅎ) 설치하고.. 2022. 10. 26.
나머지가 1이 되는 수 찾기 문제 설명 자연수 n이 매개변수로 주어집니다. n을 x로 나눈 나머지가 1이 되도록 하는 가장 작은 자연수 x를 return 하도록 solution 함수를 완성해주세요. 답이 항상 존재함은 증명될 수 있습니다. 제한사항 3 ≤ n ≤ 1,000,000 입출력 예nresult 10 3 12 11 입출력 예 설명 입출력 예 #1 10을 3으로 나눈 나머지가 1이고, 3보다 작은 자연수 중에서 문제의 조건을 만족하는 수가 없으므로, 3을 return 해야 합니다. 입출력 예 #2 12를 11로 나눈 나머지가 1이고, 11보다 작은 자연수 중에서 문제의 조건을 만족하는 수가 없으므로, 11을 return 해야 합니다. 나의 코드: #include #include #include int solution(int n.. 2022. 10. 26.