Thymeleaf 에러

zzee22su·2022년 5월 23일
0

나의 실수..ㅎ

목록 보기
1/2

에러 내용

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template [hello-api], template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause

에러 발생 위치

    @GetMapping("hello-api")
    public Hello helloApi(@RequestParam("name") String name) {
        Hello hello = new Hello();
        hello.setName(name);
        return hello;
    }

발생 원인

  • java 객체로 return 받도록 해놓은 코드에 @ResponseBody를 사용하지 않아 위와 같은 에러 발생.

@ResponseBody

  • @ResponseBody를 사용하면 http 요청 body를 자바객체로 전달받을 수 있다.

개선 방법

ResponseBody 어노테이션을 추가하여 body를 자바 객체로 받을 수 있도록 하였음.

    @GetMapping("hello-api")
    @ResponseBody
    public Hello helloApi(@RequestParam("name") String name) {
        Hello hello = new Hello();
        hello.setName(name);
        return hello;
    }
profile
BackEnd/Android

0개의 댓글