Skip to content

Instantly share code, notes, and snippets.

@ishiis
Created October 20, 2016 16:52
Show Gist options
  • Save ishiis/1af21bc06895c650a2e7e80d2a619815 to your computer and use it in GitHub Desktop.
Save ishiis/1af21bc06895c650a2e7e80d2a619815 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment