【问题标题】:I can't redirect using Spring Boot我无法使用 Spring Boot 重定向
【发布时间】:2020-04-29 05:29:14
【问题描述】:

我使用 Spring boot @scheduled 定期执行任务。我想在任务的定期执行完成后重定向并跳转到另一个页面。但是,该过程会定期执行并显示消息,但不会执行重定向。 请给我建议。

   enter code here  
   @Controller
   @RequestMapping("/index")
   public class TaskController {  
       @Scheduled(fixedRate = 5000)
       public String task(){
              System.out.println("test");
              return "redirect:/index";
       }
   }

【问题讨论】:

    标签: java spring spring-boot


    【解决方案1】:

    一个带有 schedule 注释的方法正在您的应用程序中运行,而无需与外部进行任何交互。所以没有客户端可以重定向到任何东西。
    您只能从被调用的方法重定向,因为它映射到 get 或 put 或任何其他类型的请求。

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 2019-11-10
      • 2018-10-24
      • 2017-11-28
      • 2023-04-11
      • 1970-01-01
      • 2019-10-22
      • 2015-11-20
      • 2019-02-21
      相关资源
      最近更新 更多