20221020 [Spring Boot, Vue.js]

Yeoonnii·2022년 10월 21일
0

TIL

목록 보기
51/52
post-thumbnail

테이블 생성

CREATE TABLE EXMEMBER(
ID VARCHAR2(50) PRIMARY KEY,
PW VARCHAR2(200),
NAME VARCHAR2(20),
PHONE VARCHAR2(20),
ROLE VARCHAR2(20) DEFAULT 'CUSTOMER',
REGDATE TIMESTAMP DEFAULT CURRENT_DATE
);


Spring Security 환경설정

confg파일 설정 전까지는 아래와 같이 security가 설정되어 있다

SecurityConfig.java

package com.example.config;

import org.springframework.context.annotation.Bean;
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.web.SecurityFilterChain;

@Configuration //서버가 구동시 미리 실행되는 파일
@EnableWebSecurity
public class SecurityConfig {
    
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception{
        return http.build();
    }
}

Spring Security 환경설정 후 서버를 다시 구동하면 security가 해제되어있다


HomeController.java

package com.example.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

    // 127.0.0.1:8080/ROOT/
    @GetMapping(value={"/","/home","/home.do"})
    public String homeGET(){
        return "home";
    }

}

resources/tamplates/home.html

<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>홈화면</title>
</head>

<body>
    <h3>홈화면</h3>
</body>
</html>

ExMember.java

package com.example.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.CreationTimestamp;
import org.springframework.format.annotation.DateTimeFormat;

import lombok.Data;

@Entity
@Data
@Table(name = "EXMEMBER")
public class ExMember {
    @Id
    @Column(name = "ID", length = 50)
    String id;
    
    @Column(length = 200)
    String pw;

    @Column(length = 20)
    String name;

    @Column(length = 20)
    String phone;

    @Column(length = 20)
    String role="CUSTOMER";

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm.ss.SSS")
    @CreationTimestamp
    @Column(name = "REGDATE", updatable = false)
    Date regdate = null;

}

MemberRestController.java

package com.example.restcontroller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping(value = "/api/member")
@RequiredArgsConstructor
public class MemberRestController {

    // 환경설정에 미리생성된 객체를 가져옴
    final PasswordEncoder passwordEncoder;
    final AuthenticationManager authenticationManager;

    @PostMapping(value="/join.json")
    public Map<String, Object> joinPOST(){
        Map<String, Object> map = new HashMap<>();
        try{
        }
        catch(Exception e){
        }
        return map;
    }
    
    @PostMapping(value="/login.json")
    public Map<String, Object> loginPOST(){
        Map<String, Object> map = new HashMap<>();
        try{
        }
        catch(Exception e){
        }
        return map;
    }

    @PostMapping(value="/logout.json")
    public Map<String, Object> logoutPOST(){
        Map<String, Object> map = new HashMap<>();
        try{
        }
        catch(Exception e){
        }
        return map;
    }

    @GetMapping(value="/selectone.json")
    public Map<String, Object> selectOnePOST(){
        Map<String, Object> map = new HashMap<>();
        try{
        }
        catch(Exception e){
        }
        return map;
    }

    @PutMapping(value="/update.json")
    public Map<String, Object> updatePUT(){
        Map<String, Object> map = new HashMap<>();
        try{
        }
        catch(Exception e){
        }
        return map;
    }

    @DeleteMapping(value="/delete.json")
    public Map<String, Object> deleteDELETE(){
        Map<String, Object> map = new HashMap<>();
        try{
        }
        catch(Exception e){
        }
        return map;
    }
}

ExMemberRepository.java

package com.example.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.example.entity.ExMember;

@Repository
public interface ExMemberRepository extends JpaRepository<ExMember, String>{
    
}

0개의 댓글