Spring

Spring-boot 신규 프로젝트 만들기 (2)

정리하고기록하자 2023. 11. 28. 14:22
반응형

간단한 웹 애플리케이션으로 /hello URL 호출 할 경우 내가 만든 이미지리스트 가져와보기

 


  • Controller 생성하기

  • 소스코드
package com.example.demo;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/hello")
public class ImgController {

	@GetMapping()
	public String selImgList(Model model){
		return "imgList";
	}
}
  • @Controller : Model 객체를 만들어 데이터를 담고 View를 반환하는 것이다.
  • @RequestMapping : 특정 Url로 요청을 보내면 Contoller에서 어떠한 방식으로 처리할지 정의를 하는데
    이때 들어온 요청을 특정 메서드와 매핑하기 위해 사용하는 것.
    • @GetMapping()
    • @PostMapping()
    • @PutMapping()
    • @DeleteMapping()

  • 만든 html / js / plugins / sample 폴더 넣었고 


 

  • 실행 해보기

 

 

 

반응형