0

I want to response a type of String as "redirect:http://www.stackoverflow.com" and expected that the browser would auto redirect to the address as what I want. But, it was failed when I use a "@RestController".(based on SpringBoot 1.3.5.RELEASE)

@RestController    
@RequestMapping("/test")
public class TestRestController {

    @RequestMapping("/rest_controller")
    public String testResponse() {
        return "redirect:http://stackoverflow.com/";
    }
}

but the following can make the redirect succeed when use "@Controller".

@Controller    
@RequestMapping("/test")
public class TestController {   
    @RequestMapping("/not_rest_controller")
    public String testResponse() {
        return "redirect:http://stackoverflow.com/";
    }
}

and I want to know how to make the @RestController also succeed as the @Controller.

Jarvis
  • 371
  • 1
  • 10
  • 22
  • 1
    Why do you want to force `@RestController`instead of `@Controller` ? – Mickael Jul 06 '16 at 10:12
  • 2
    A RestController is a specialized Controller which is intended to return the return value as response body. So if you don't want that, don't use it. Controller is for what you want to do. – dunni Jul 06 '16 at 10:14
  • @MickaëlB sometimes, I make a class as `@RestController`, and I want to response a `String` to tell the browser to redirect as what I want at a mapping `@RequestMapping`. But now I have to make a new class and have to annotate it with `@Controller`. so I want to know if there have sth special way that I don't have to make a new class and make it possible by `@RestController` . – Jarvis Jul 06 '16 at 14:15

0 Answers0