Spring MVC “duplicates” parts of the URL

后端 未结 4 1444
攒了一身酷
攒了一身酷 2021-02-14 12:14

I have a simple @Controller within a spring-mvc environment. This is the Controller:

@Controll         


        
4条回答
  •  萌比男神i
    2021-02-14 12:43

    I guess it's related to default view name resolution.

    If you want a value returned by your handler method to be encoded as response body (in JSON, XML, etc), you need to annoate the method with @ResponseBody, or annotate the whole controller with @RestController (in Spring 4.x).

    Otherwise, Spring tries to render a view with your return as model attribute. And since you didn't provide a name of a view to render, Spring tries to deduce it from request URL.

提交回复
热议问题