spring 시작하기

이태규·2022년 2월 25일
0

spring

목록 보기
1/64
  1. 라이브러리 설치 파일명 : pom.xml
    <!-- web을 사용하게 해줌. 크롬에서 접속가능하게 -->
    <dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>

	<!-- web server 실제로 web을 크롬에서 오는 주소를 인식해서 표시해주는-->
	<dependency>
		<groupId>org.apache.tomcat.embed</groupId>
		<artifactId>tomcat-embed-jasper</artifactId>
		<scope>provided</scope>
	</dependency>

    <!-- 소스코드가 변경되면 tomcat을 자동으로 재시작 시켜줌-->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-devtools</artifactId>
		<scope>runtime</scope>
		<optional>true</optional>
	</dependency>
	
	<!-- jsp에서 사용하기 -->
	<dependency>

org.springframework.boot
spring-boot-starter-thymeleaf


2 . 환경설정 파일명 : resources/application.properties

포트번호 설정
server.port=8080

devtools 설정
spring.devtools.livereload.enabled=true

jsp위치 설정(어느폴더에 어떤확장자)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.jsp


  1. 컨트롤러 생성
    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/home
@GetMapping(value = "/home")
public String homeGET(){
    //home.jsp 표시하기
    return "home";
}

// 127.0.0.1:8080/join
@GetMapping(value = "/join")
public String joinGET(){
    // join.jsp 표시하기
    return "join";
}

}


  1. jsp 생성 resources/templates/ 확장자가 .jsp인것만 인식

  1. 실행
package com.example.boot_20220225;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication

// 임의로 만든 controller의 위치를 설정 
@ComponentScan(basePackages = {"com.example.controller"})
public class Boot20220225Application {

	public static void main(String[] args) {
		SpringApplication.run(Boot20220225Application.class, args);
		System.out.println("hello world");
	}

}
profile
한 걸음씩 나아가자

0개의 댓글