Java 如何在springboot facebook集成中处理页面刷新?

Java 如何在springboot facebook集成中处理页面刷新?,java,facebook,spring-boot,Java,Facebook,Spring Boot,我正在尝试实现基于facebook的登录。一切正常,但我不知道如何处理刷新情况,即一旦用户被重定向到页面,并且用户单击刷新,它将触发另一个请求,我如何处理 package com.example.demo.controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springfra

我正在尝试实现基于facebook的登录。一切正常,但我不知道如何处理刷新情况,即一旦用户被重定向到页面,并且用户单击刷新,它将触发另一个请求,我如何处理

package com.example.demo.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import com.example.demo.FbService.FbService;

@Controller
@RequestMapping("/")
public class FbController {

    @Autowired
    private FbService facebookService;

    @GetMapping("/createFacebookAuthorization")
    public RedirectView createFacebookAuthorization(){
        return new RedirectView(facebookService.createFacebookAuthorizationURL());
    }

    @GetMapping("/facebook")
    public String createFacebookAccessToken(@RequestParam("code") String code){
        String accToken=facebookService.createFacebookAccessToken(code);
        Object obj=facebookService.getName(accToken);
        return "details";
    }

    @RequestMapping("/")
    public ModelAndView firstPage() {
        return new ModelAndView("welcome");
    }

}
details.html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Login</title>

</head>
<body>
<div style="border: 1px solid #ccc; padding: 5px; margin-bottom: 20px;">

   Welcome  

</div>
</body>
</html>



登录
欢迎

登录
|  
发送请求的起始页

工作正常的重定向页面 刷新完成后出现的错误

我知道它为什么会来,但不知道怎样才能预防它。
任何帮助都将不胜感激。

发生这种情况是因为您试图第二次将
code
参数交换为令牌,但这只能一次完成。您的系统可能会根据URL中存在的参数自动触发此操作。因此,在您将其交换为令牌后,重定向到不带该参数的其他URL。明白了。非常感谢。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Login</title>

</head>
<body>
<div style="border: 1px solid #ccc; padding: 5px; margin-bottom: 20px;">

   Welcome  

</div>
</body>
</html>


<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Login</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width" />
<base href="/" />
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="/webjars/font-awesome/css/font-awesome.min.css"></link>
</head>

<body>

<div style="border: 1px solid #ccc; padding: 5px; margin-bottom: 20px;">
    <a href="/createFacebookAuthorization">Validate using Facebook</a> |  
</div>

</body>
</html>