java - Spring: Implement a share-via-link feature for web application
问题描述
I have a requirement where I need to implement a share-application-state-via-link
feature.
My application is a video streaming single page application consisting of some dropdown options for user to filter out available videos and a video player to play the selected videos.
Now first on the basis of dropdown options , a user selects the available videos and add it to video player. At max 4 videos could be added. Now after that, I need to share this state of my application to some other user so I get a share link(just like Share answer in StackOverflow) and I send this to other user. This other user just need to hit this URL and it will load the exact state of application with videos added to player and dropdown populated with respective options.
My Approach:
I have a /getVideo
rest service
which fetches the video data and send it as json
response back to angular
based frontend. I have created a Share
button which when clicked, creates a link by adding all the selected dropdown options something like:
https://localhost:8080/MyApp/shared?genre=Action&type=web-series
I have created a method /shared
which will take these params and call the /getVideo
internally.
The problem here is, I need to load index.html
when the above link is hit. I also have to send the getVideo data to be loaded with index.html
and the application should function properly. Am not able to solve this problem and need help.
Is my approach correct? Is there any alternate way? Am using Spring-Boot
for backend and angular2
for frontend.
Here is the /shared
API:
@RequestMapping(value = "/shared", method = RequestMethod.GET)
public String getSharedVideo(RedirectAttributes redirectAttributes,
@RequestParam(value="genre", required=false) String genre,
@RequestParam(value="date", required=false) String date,
@RequestParam(value="type", required=false) String type,
@RequestParam(value="version", required=false) String version,
@RequestParam(value="category", required=false) String category
){
List<Lab> lab = null;
try {
lab = videoService.getVideo(genre, date, type, version, category);
redirectAttributes.addAllAttributes(lab); // how to send this data to frontend
return "index.html";
} catch(Exception e) {
LOGGER.error("EXCEPTION - " + e.getMessage());
}
Any help would be appreciated.
解决方案
推荐阅读
- r - 在加权无向图中测量社区之间的距离
- vba - 公式计算出值后,如何将公式更改为静态值?
- java - 在spring boot中创建一个REST API来上传Multipart文件数据
- macos - 什么是 CGEvent 中的像素单元(CGScrollEventUnit.pixel)?
- postgresql - Heroku Postgres 在排序时忽略下划线
- amazon-web-services - 我正在尝试将 csv 文件导入 HDFS。我收到一个错误,指出:-cp:没有足够的参数预期 2 但得到 1?
- sql - 需要帮助在 Oracle 中创建正确的联接
- youtube - 如何获取已删除的 YouTube 视频和订阅者?
- vue.js - 如何在d3中制作多系列条形图?
- struts2 - 我们可以直接将 Struts 从 Struts 2.0 迁移到 Struts 2.5 吗?