Fullstack-Study-241204-250625

커리큘럼(12-30/변경)

01. Java
02. git
03. Database 
04. Jsp [Server]

05. HTML,CSS 
07. JS
06. 미니프로젝트-2W

08. SpringFramework , SrpingBoot (v)
09. React JS [Front-end]
10. 중간프로젝트 (1M)
11. Linux 명령어
12. AWS 클라우드
13. DevOps - Docker
14. App - Android
15. 최종프로젝트 (1M)

스프링 부트

스프링과의 차이

스프링 스프링부트
프로젝트의 구조 MVC2 MVC2
빌드 툴 MAVEN GRADLE
빌드 설정파일 Pom.xml Build.gradle
스프링 설정파일 xml파일 java파일 & Application.properties
설정 방식 수동 자동
JDBC Mybatis Mybatis & JPA
View에 대한 처리 JSP Thymleaf or JSP 등
어노테이션 기존 기존 + @

스프링부트 기본 설정

롬복(Lombok)

  • VO(DTO)의 생성자, getter, setter를 자동으로 생성해주는 라이브러리
  • IntelliJ에 적용 : File > Settings > Plugins에서 Lombok 설치 후 재시작
  • Lombok설정 확인 : Annotation Processors > Enable annotation processing을 체크
  • Lombok 사용

@NoArgsConstructor

@AllArgsConstructor

@Data

= @Getter + @Setter + @ToString

@NoArgsConstructor // 기본생성자
@AllArgsConstructor // 멤버변수를 받는 생성자
//@Getter
//@Setter
//@ToString
@Data // getter + setter + toString를 합침
public class TestVO {

    // 단축키 alt + insert
    
    private String id;
    private String pw;
    private String name;
    private int salary;
    private String address;
    private LocalDateTime hiredate;
}

View 선택

JSP를 뷰로 적용

  1. gradle 파일
  1. application.properties 파일
  1. 프로젝트의 구조를 Spring과 동일하게 구성

src > main > webapp > WEB-INF > views > jsp파일

스프링부트 IOC컨테이너 bean설정

@Configuration // 이 클래스를 스프링의 자바설정파일로 씀
public class WebConfig implements WebMvcConfigurer {

    @Bean // 스프링이 이 메서드를 호출 시켜서 반환되는 값을 bean으로 등록 시킴
    public void myTest(){

        System.out.println("설정 파일 동작함");

    }

    @Bean
    public TestServiceImpl testServiceImpl(){
        return new TestServiceImpl();
    }

}

ApplicationContext

    @Value("${server.port}")
    private String port; // application-properties 참조
    
    @Value("${my.example.port}")
    private String myport; // application-production.properties참조

    @Autowired
    private ApplicationContext applicationContext; // IOC컨테이너로 동작하는 객체
    
    @Bean // 스프링이 이 메서드를 호출 시켜서 반환되는 값을 bean으로 등록 시킴
    public void myTest(){

        System.out.println("설정 파일 동작함");

        System.out.println("빈의 개수"+ applicationContext.getBeanDefinitionCount());
        HomeController controller= applicationContext.getBean(HomeController.class); // 이 타입 bean객체를 찾음
        System.out.println("ioc컨테이너안에 컨트롤러 객체:"+controller);

        System.out.println("프로퍼티파일의 port값: "+port);
        System.out.println("프로덕션-프로퍼티파일의 port값:"+myport);
    }

테스트코드 사용

Builder패턴(클래스 디자인 패턴)

내부클래스

  • 클래스안에 클래스
  • 내부 클래스 종류
  • inner클래스 : 안에서 밖으로 접근이 가능(외부참조 가능)
  • static inner 클래스 : 안에서 밖으로 접근이 불가능(외부참조 불가능)
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
public class TestBuilderVO {
    
    // 빌더패턴이란 - 객체의 불변성을 위해서 사용하는 스프링이 애용하는 문법

    // 1. 멤버변수
    private String name;
    private int age;

    /*
    // 3. 외부클래스가 생성될때 내부클래스인 Builder를 매개변수로 받음
    private TestBuilderVO(Builder builder){
        this.name = builder.name;
        this.age = builder.age;
    }

    // 4. 외부에서 객체 생성을 요구할 때 builder메서드를 호출하도록 함
    public static Builder builder(){
        return new Builder(); // 내부클래스 반환
    }

    //7. toString의 오버라이딩
	@Override
	public String toString() {
		return "BuilderVO [name=" + name + ", age=" + age + "]";
	}
	
    // 2. 내부클래스
    public static class Builder{
        private String name;
        private int age;


        // 생성자 제한
        private Builder(){}

        // 5. 빌더클래스에서는 set메서드만 생성하고, 자신을 반환시킴
        public Builder setName(String name){
            this.name = name;
            return this;
        }

        public Builder setAge(int age){
            this.age = age;
            return this;
        }

        // 6. build메서드를 호출하면 3번의 생성자를 통해서 멤버변수를 외부에 저장시킴
        public TestBuilderVO build(){
            return new TestBuilderVO(this);
        }
    }
     */

}
public class Car {
    private final String color;
    private final String engine;
    private final int seats;

    // private 생성자 (빌더 패턴을 통해서만 생성 가능)
    private Car(Builder builder) {
        this.color = builder.color;
        this.engine = builder.engine;
        this.seats = builder.seats;
    }

    // Getter
    public String getColor() {
        return color;
    }

    public String getEngine() {
        return engine;
    }

    public int getSeats() {
        return seats;
    }

    @Override
    public String toString() {
        return "Car [color=" + color + ", engine=" + engine + ", seats=" + seats + "]";
    }

    // Builder 클래스
    public static class Builder {
        private String color;
        private String engine;
        private int seats;

        // 각 필드를 설정하는 메서드
        public Builder setColor(String color) {
            this.color = color;
            return this;
        }

        public Builder setEngine(String engine) {
            this.engine = engine;
            return this;
        }

        public Builder setSeats(int seats) {
            this.seats = seats;
            return this;
        }

        // 최종 객체를 생성하는 build 메서드
        public Car build() {
            return new Car(this);
        }
    }

    public static void main(String[] args) {
        // Builder 패턴으로 객체 생성
        Car car = new Car.Builder()
                        .setColor("Red")
                        .setEngine("V8")
                        .setSeats(4)
                        .build();

        System.out.println(car);
    }
}

타임리프

<h3 th:text="${'hello World'}"></h3>
<h3>[[${'hello World'}]]</h3>

th:with

<div th:with="a=10">
    [[${a}]]
</div>

th:if , th:unless

<div th:with="a=230">
    <span th:if="${a==20}">20입니다</span>
    <span th:unless="${a==20}">20이 아닙니다</span>
</div>
<div th:with="a=10">
    [[${a==10?'같음':'다름'}]]
</div>