---------------------------어플리케이션
package com.bookStudy.boo.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args){
SpringApplication.run(Application.class,args);
}
}
프로젝트의 메인 클래스 이다. 어노테이션을 통해 스프링부트 자동설정 스프링 빈 읽기 생성 모두
자동으로 설정됨. 항상 프로젝트 최상단의 위치해야됨.
SpringApplication.run(Application.class,args) -> 내장 WAS 실행
스프링 부트로 만들어진 Jar파일로 실행하면된다.
---------------------------컨트롤러
package com.bookStudy.boo.springboot.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController //컨트롤러를 json을 반환하는 컨트롤러로 만들어줌 ResponsBody를 이렇게 한번선언해주면 다사용가능?
public class HelloController {
@GetMapping("/hello")
public String hello() {
return "hello";
}
@GetMapping("/hello/dto")
public HelloResponseDto helloDto(@RequestParam("name") String name, @RequestParam("amount") int amount){
return new HelloResponseDto(name, amount);
}
}
///Test code