package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/**
* Created by ishiis on 16/10/21.
*/
@Controller
public class RedirectController {
@RequestMapping(method = RequestMethod.GET, value = "/redirect")
public String redirectToSample(RedirectAttributes redirectAttributes) {
redirectAttributes.addAttribute("aaa", "bbb");
return "redirect:http://localhost:8080/api/users";
}
}
$ curl -i http://127.0.0.1:8080/redirect
HTTP/1.1 302
Location: http://localhost:8080/api/users?aaa=bbb
Content-Language: ja-JP
Content-Length: 0
Date: Thu, 20 Oct 2016 16:45:54 GMT