最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring mvc - Reloading Sprint MVC view through TimerTask - Stack Overflow

programmeradmin0浏览0评论

I'm creating a web page using Spring which refreshes the page at regular intervals in order to show up-to-date data. Below is a condensed version of my code which uses Timer for scheduling the refresh after 5 seconds for testing purposes.

@Controller
public class IndexController {
    private String id;
    private Timer refreshTimer = new Timer();

    @GetMapping("/{id}")
    public String greeting(@PathVariable String id, Model model) {
        this.id = id;
        refreshTimer.schedule(new RefreshTask(), 5000L);
        return "index";
    }

    private class RefreshTask extends TimerTask {
        @Override
        public void run() {
            // refresh view
        }
    }
}

However, about the only information I've found about refreshing views is having a @RequestMapping method return the url prefixed with "redirect:". Is it possible to refresh the view using TimerTask.run() or similar methods without waiting for the view to send a request?

发布评论

评论列表(0)

  1. 暂无评论