java - 我无法使用 Spring Boot 重定向
问题描述
我使用 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";
}
}
解决方案
一个带有 schedule 注释的方法正在您的应用程序中运行,而无需与外部进行任何交互。所以没有客户端可以重定向到任何东西。
您只能从被调用的方法重定向,因为它映射到 get 或 put 或任何其他类型的请求。
推荐阅读
- c++ - 是否有一个 CGAL 函数来检查孔是否实际上在带孔的多边形内或检查带孔的多边形是否有效?
- android - 在我的情况下,如何更改仅图标切换按钮中的图标颜色?
- excel - 需要设计一个公式从自由格式文本框中提取“DE12345”
- java - 必须定义 GOOGLE_APPLICATION_CREDENTIALS
- group-by - 如何在 Diesel 中编写 GROUP BY 或 HAVING 子句?
- javascript - 需要使锚标记转到特定的ID,同时为固定标头腾出空间
- powerbi - 基于 ID 和日期计算平均值的 DAX 函数
- reactjs - Redux 对 .splice() 的不良影响
- android - Android 6.0.1 上的 Flutter Camera 视频录制抛出错误
- video - AMP 在向下滚动时停止视频