How To Implement a progress bar using Spring 3 MVC?

后端 未结 2 1037
灰色年华
灰色年华 2021-02-20 08:57

Can anyone teach me or direct to a working example to satisfy this requirement.

Scenario:

  1. List item My Web App is using spring mvc.
  2. One of the ser
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 09:46

    There are a good number of ways to handle a scenario like this. One way is to model the work in terms of a "Process", which contains a "status", including a percentage completion.

    If you imagine what this might look like on a website, clicking the button to start the process would submit a form that begins the process and assigns some sort of identity to the process, almost like if you were creating any other sort of object. It would then redirect you to a "process status" page.

    The process status page would query for the status of the process and display it. It'd probably have a URL parameter for the process's ID. It would perhaps update itself using an AJAX call to return a progress percentage.

    On the backend, you now need to solve a couple of problems: finding out the current status of process N, and updating the status of process N. You could accomplish this in a number of ways, including storing the progress in the database or having some sort of in-memory table of running jobs. You could also use some sort of heuristic to estimate a percent. For example, if it's a "register new user" job, maybe it's 20% done if the user's table has an email address, 40% done if the user avatar table has data in it for this user, etc. I don't recommend this as much.

提交回复
热议问题