프로젝트

5. db 연동

uni5948 2021. 11. 18. 21:13

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 접속

DB 접속

조금 전 만든 USER 테이블이 생성된 것을 확인할 수 있다.

USER 테이블 확인

 

'프로젝트' 카테고리의 다른 글

7. 로그인  (0) 2021.11.22
6. 회원가입  (0) 2021.11.18
4. 보안 해제  (0) 2021.11.18
3. 환경설정  (0) 2021.11.18
2. 프로젝트 생성  (0) 2021.11.18