728x90
반응형
SMALL

Spring 설정부터!!

  • 인텔리제이에서 spring 설정!   Spring Boot 2.7.5 으로 설정하기
    • Spring Data JPA
    • H2 Database
    • Thymeleaf
    • Spring Boot DevTools
    • Lombok
    • Spring Web

 

  • index.html 만들기

src > main > resources > templates 에 아래 index.html을 만들기

  • 테이블 Blog만들기
  • entity패키지에 Blog이름의 클래스 생성!
@Getter
@Entity
@NoArgsConstructor
public class Blog extends Timestamped{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id; // 기본키 설정!
    @Column(nullable = false)
    private String username;
    @Column(nullable = false)
    private String contents;
    @Column(nullable = false)
    private String titlename;
    @Column(nullable = false)
    private String password;
}

 

  • Timestamped - entity패키지에 Timestamped이름의 클래스 생성!
package com.example.myblog.entity;

import lombok.Getter;

import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

@Getter
@MappedSuperclass
@EntityListeners(AbstractMethodError.class)
public class Timestamped {
    
    private LocalDateTime createdAt;
    
    private LocalDateTime modifiedAt;
}
  • repository - BlogRepository 라는 인터페이스를 생성!
package com.example.myblog.repository;

import com.example.myblog.entity.Blog;

public interface BlogRepository extends JpaRepository<Blog, Long>{  // JpaRepository 추후에 만들고 적용시키기!
}
  • application.properties
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:db;MODE=MYSQL;
spring.datasource.username=sa
spring.datasource.password=

spring.thymeleaf.cache=false
728x90
반응형
LIST

+ Recent posts