5. db 연동
참조 : Spring 일지 #44
- entity 생성
package com.example.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Entity
@Setter
@Getter
@NoArgsConstructor
@ToString
@Table(name = "USER")
public class User {
@Id
@Column(name = "USERID")
private String userid = null;
@Column(name = "USERPW")
private String userpw = null;
@Column(name = "USERNAME")
private String username = null;
}
- db 연동
더보기
package com.example.security;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration //환경설정 파일
@EnableWebSecurity //security를 적용
public class SecurityConfig extends WebSecurityConfigurerAdapter{ @Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
-------------추가------------- //h2 console 사용
http.csrf().disable();
http.headers().frameOptions().sameOrigin();
-------------추가-------------
}
}
- db 접속
조금 전 만든 USER 테이블이 생성된 것을 확인할 수 있다.