복붙노트

[SPRING] {}가있는 Spring MVC @Path 변수

SPRING

{}가있는 Spring MVC @Path 변수

스프링 부트를 사용하여 응용 프로그램을 개발하고 있습니다. REST 컨트롤러에서는 path 변수 (@PathVariabale annotation)를 사용하는 것을 선호합니다. 경로 변수를 가져 오는 내 코드는 contatins {}가 URL에있는 것처럼 중괄호를 사용합니다. 아무도 나에게이 문제를 해결하라고 제안 해주세요.

@RequestMapping(value = "/user/item/{loginName}", method = RequestMethod.GET)
public void getSourceDetails(@PathVariable String loginName) {
    try {
        System.out.println(loginName);
        // it print like this  {john}
    } catch (Exception e) {
        LOG.error(e);
    }
}

URL

http://localhost:8080/user/item/{john}

컨트롤러의 출력

{남자}

해결법

  1. ==============================

    1.대신 http : // localhost : 8080 / user / item / john을 사용하여 요청을 제출하십시오.

    대신 http : // localhost : 8080 / user / item / john을 사용하여 요청을 제출하십시오.

    Spring 변수 loginName에 "{john}"값을 부여하므로 Spring은 "{}"

    웹 MVC 프레임 워크는

    @RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
     public String findOwner(@PathVariable String ownerId, Model model) {
         Owner owner = ownerService.findOwner(ownerId);
         model.addAttribute("owner", owner);
         return "displayOwner"; 
      }
    
  2. from https://stackoverflow.com/questions/26794198/spring-mvc-path-variable-with-braces by cc-by-sa and MIT license