본문 바로가기
개발자의 정보/Java & framework

FrontEnd 분리된 SpringMVC 구성시 Controller 구성

by pastory 2020. 2. 1.

welcome controller 생성

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


import javax.servlet.http.HttpServletRequest;


@Slf4j
@Controller
public class DefaultController {
   
   @RequestMapping(value = {""}, produces = {"text/html"})
   public String index(HttpServletRequest req) {
      log.info("index request: {}", req.getRequestURL());
      return "index.html";
   }
}

 

error controller 생성

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;


@Controller
public class DefaultErrorController implements ErrorController {
   
   @GetMapping("error")
   public String error() {
      return "index.html";
   }
   
   @Override
   public String getErrorPath() {
      return "error";
   }
}

 

댓글