spring4.0以后出来的这个注解,简而言之就是@RestController = @Controller + @ResponseBody,这让我们既可以标注为controller层,也可以直接返回json数据
之前我们写代码是这样子的
@Controller
@ResponseBody
public class controllerTest { }
@RestController
public class restControllerTest { }
用完注解有一些疑问,返回变成json数据,那我们重定向或者转发怎么办?
搜集了如下解决方案
1、转发
@RequestMapping(value="/login", method=RequestMethod.POST)
public ModelAndView login(){
ModelAndView mv = new ModelAndView("index");
return mv;
}
2、重定向@RestController
public class FooController {
@RequestMapping("/foo")
void handleFoo(HttpServletResponse response) throws IOException {
response.sendRedirect("some-url");
}
}