SpringMVC 方法裡返回json或跳到一個頁面
習慣了用@ResponseBody來與移動端互動,忽然有個新的需求,如果移動端傳遞的引數是XX,則跳到一個頁面。所以@ResponseBody不能用了,用回最原始的out.write();
@RequestMapping("/xxxxxx")
public String getUrl(HttpServletRequest request, @RequestParam( "url") String url,
HttpServletResponse response, PrintWriter out) {
ResponseData responseData;
if (null != url) {
return "redirect:" + url;
}
response.setContentType("text/html;charset=utf-8");
response.setHeader("pragma", "no-cache");
response.setHeader("cache-control", "no-cache");
out.write("{\"xxx\":"\xxxx\"}");
return null;
}