处理流程(不清楚spring的流程),所以现阶段采用了传统的处理流程
- 通过ajax 响应前端的onload事件,然后发送请求
onload方法的标签有:<body>, <frame>, <frameset>, <iframe>, <img>, <link>, <script>
<script >
function getStreamingMovies() {
var Data = null;
$.ajax({
url:'http://localhost:8080/getStreamingMovies',
type:"get",
dataType:"json",
success : function() {},
}
)
}
/script>
<div class="leftside">
<div class="hot">
<div class="subtitle">
<h2>精选电影推荐(8部)</h2>
<a href="#">全部></a>
</div>
<div class="movies">
<style onload="getStreamingMovies()"></style>
<c:forEach items="${sessionScope.userStreamingRecommend}" var="item">
<a href="#" class="first">
<img src="${item.image_path.concat('poster.jpg')}" alt="movies" height="220" width="160" >
<!-- 后续添加宽高限制 -->
<div>${item.title}:${item.vote_average}</div>
</a>
</c:forEach>
</div>
</div>
</div>
2.将Ajax请求去响应Rest层的getStreamingMovies
//调用业务处理层的方法获取实时推荐的电影信息
@RequestMapping("/getStreamingMovies")
public void getRealTimeMovies(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html; charset=UTF-8");
HttpSession session = request.getSession();
PrintWriter out = response.getWriter();
UserService userService = new UserService();
RecommendService recommendService = new RecommendService();
MoviesService moviesService = new MoviesService();
String username =(String) session.getAttribute("username");
// String username="kurumi";
String userIdAndGenres = userService.getUserIdByUsername(username);
String[] user = userIdAndGenres.split(":");
ArrayList<Recommendation> streamingRecommendation = recommendService.getStreamingRecommendation(
new GetMovieRequest(Integer.parseInt(user[0]), Constant.STREAMING_RECOMMEND_NUM));
//当前没有实施推荐的项目
if (streamingRecommendation==null) {
streamingRecommendation = recommendService.getGenresTop(new GetTopMovieGenresRequest(user[1],Constant.STREAMING_RECOMMEND_NUM));
}
//根据电影id获取详细的电影详细
ArrayList<Movie> moviesList = moviesService.getMoviesList(streamingRecommendation);
ArrayList<Movie> recommendList = InfoParse.movieImageParse(moviesList);
session.setAttribute("userStreamingRecommend",recommendList);
}
3.jsp页面通过foreach标签库获得对应的值
<style onload="getStreamingMovies()"></style>
<c:forEach items="${sessionScope.userStreamingRecommend}" var="item">
<a href="#" class="first">
<img src="${item.image_path.concat('poster.jpg')}" alt="movies" height="220" width="160" >
<!-- 后续添加宽高限制 -->
<div>${item.title}:${item.vote_average}</div>
</a>
</c:forEach>
附上 jsp代码 只完成了部分功能
<%@ page import="org.cuit.serviceProcess.model.recommand.Recommendation" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="org.cuit.serviceProcess.model.info.Movie" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>首页</title>
<script src="../layui/jquery.min.js"></script>
<link rel="stylesheet" href="../css/indexstyle.css">
<script src="../layui/layui.js" charset="utf-8"></script>
<link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
<!-- 导航栏 -->
<div class="nav">
<div class="typeArea">
<img src="images/logo.png" alt="logo" class="logo">
<ul>
<li class="selected"><a href="#">首页</a></li>
<li><a href="#">电影</a></li>
<li><a href="#">影院</a></li>
<li><a href="#">演出</a></li>
<li><a href="#">榜单</a></li>
<li><a href="#">热点</a></li>
<li><a href="#">商城</a></li>
</ul>
<div class="app">
<div class="down"> APP下载</div>
<div class="triangle"></div>
</div>
<div class="searchBox">
<input type="text" name="search" id="search" placeholder="电影搜索">
<button></button>
</div>
<div class="user">
<img src="images/headPhoto.png" alt="headPhoto">
<div class="triangle"></div>
</div>
</div>
</div>
<script >
function getStreamingMovies() {
var Data = null;
$.ajax({
url:'http://localhost:8080/getStreamingMovies',
type:"get",
dataType:"json",
success : function() {},
}
)
}
function load2() {
var Data = null;
$.ajax({
url:'http://localhost:8080/test222',
type:"get",
dataType:"json",
success : function() {},
}
)
}
</script>
<%
//获取用户名
String username = (String)session.getAttribute("username");
session.setAttribute("username",username);
//实时推荐
// ArrayList<Movie> streamingRecommend = (ArrayList<Movie>) session.getAttribute("userStreamingRecommend");
//
//// for (Movie movie : streamingRecommend) {
//// System.out.println(movie);
//// }
// request.setAttribute("streamingRecommend",streamingRecommend);
%>
<%--<script>--%>
<%-- layui.use(['rate'], function(){--%>
<%-- var rate = layui.rate;--%>
<%-- rate.render({--%>
<%-- elem: '#test1'--%>
<%-- ,value: 2.5--%>
<%-- //是否可以选择半星--%>
<%-- ,half: true--%>
<%-- ,theme: '#FE0000'--%>
<%-- })--%>
<%-- });--%>
<%--</script>--%>
<!-- 导航栏结束 -->
<!-- 网页主体 -->
<div class="webmain">
<!-- 左侧 -->
<div class="leftside">
<div class="hot">
<div class="subtitle">
<h2 >你可能感兴趣的(8部)</h2>
<a href="#">全部></a>
</div>
<div class="movies">
<style onload="getStreamingMovies()"></style>
<c:forEach items="${sessionScope.userStreamingRecommend}" var="item">
<a href="#" class="first">
<img src="${item.image_path.concat('poster.jpg')}" alt="movies" height="220" width="160" >
<!-- 后续添加宽高限制 -->
<div>${item.title}:${item.vote_average}</div>
</a>
</c:forEach>
</div>
</div>
</div>
<div class="leftside">
<div class="hot">
<div class="subtitle">
<h2>精选电影推荐(8部)</h2>
<a href="#">全部></a>
</div>
<div class="movies">
<style onload="getStreamingMovies()"></style>
<c:forEach items="${sessionScope.userStreamingRecommend}" var="item">
<a href="#" class="first">
<img src="${item.image_path.concat('poster.jpg')}" alt="movies" height="220" width="160" >
<!-- 后续添加宽高限制 -->
<div>${item.title}:${item.vote_average}</div>
</a>
</c:forEach>
</div>
</div>
</div>
<div class="leftside">
<div class="hot">
<div class="subtitle">
<h2>最近上映的(12部)</h2>
<a href="#">全部></a>
</div>
<div class="movies">
<a href="#" class="first">
<img src="images/mov.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov2.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov3.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov4.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#" class="first">
<img src="images/mov5.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov6.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov7.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov8.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
</div>
</div>
</div>
<div class="leftside">
<div class="hot">
<div class="subtitle">
<%-- 按电影评分进行 --%>
<h2>电影榜单(12部)</h2>
<a href="#">全部></a>
</div>
<div class="movies">
<a href="#" class="first">
<img src="images/mov.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov2.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov3.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov4.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#" class="first">
<img src="images/mov5.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov6.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov7.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
<a href="#">
<img src="images/mov8.jpg" alt="movies">
<!-- 后续添加宽高限制 -->
<div>购票</div>
</a>
</div>
</div>
</div>
<!-- 右侧 -->
<div class="rightside">
<!-- 热门电影 评分数 -->
<div class="todayMoney">
<h2>热门电影</h2>
<div class="top1">
<a href="#">
<div class="firstImg">
<img src="images/top.png" alt="top" class="top">
<img src="images/top1.jpg" alt="top1post">
</div>
<div class="firstInfo">
<h3>十年一品温如言</h3>
<p>6666.66万</p>
</div>
</a>
</div>
<ul>
<li><a href="#">
<div class="num top3">2</div>
<h3>好想爱你</h3>
<div class="money">5555.55万</div>
</a></li>
<li><a href="#">
<div class="num top3">3</div>
<h3>不要忘记我爱你</h3>
<div class="money">4444.44万</div>
</a></li>
<li><a href="#">
<div class="num">4</div>
<h3>长津湖</h3>
<div class="money">3333.33万</div>
</a></li>
<li><a href="#">
<div class="num">5</div>
<h3>这个杀手</h3>
<div class="money">2222.22万</div>
</a></li>
</ul>
<div class="todayBigP">
<div class="text">今日大盘</div>
<div class="info">
<div class="detail">
<em>1.35</em>
<p>亿</p>
<a href="#">查看更多></a>
</div>
<div class="time">北京时间 09:09:06 猫眼专业版实时票房数据</div>
</div>
</div>
</div>
<!-- 今日票房板块结束 -->
<!-- 今日票房板块 -->
<div class="todayMoney">
<h2>今日票房</h2>
<div class="top1">
<a href="#">
<div class="firstImg">
<img src="images/top.png" alt="top" class="top">
<img src="images/top1.jpg" alt="top1post">
</div>
<div class="firstInfo">
<h3>十年一品温如言</h3>
<p>6666.66万</p>
</div>
</a>
</div>
<ul>
<li><a href="#">
<div class="num top3">2</div>
<h3>好想爱你</h3>
<div class="money">5555.55万</div>
</a></li>
<li><a href="#">
<div class="num top3">3</div>
<h3>不要忘记我爱你</h3>
<div class="money">4444.44万</div>
</a></li>
<li><a href="#">
<div class="num">4</div>
<h3>长津湖</h3>
<div class="money">3333.33万</div>
</a></li>
<li><a href="#">
<div class="num">5</div>
<h3>这个杀手</h3>
<div class="money">2222.22万</div>
</a></li>
</ul>
<div class="todayBigP">
<div class="text">今日大盘</div>
<div class="info">
<div class="detail">
<em>1.35</em>
<p>亿</p>
<a href="#">查看更多></a>
</div>
<div class="time">北京时间 09:09:06 猫眼专业版实时票房数据</div>
</div>
</div>
</div>
<!-- 今日票房板块结束 -->
</div>
</div>
<%--<!-- 网页底部栏 -->--%>
<%--<div class="foot">--%>
<%-- <div class="text">--%>
<%-- <div class="redLink">--%>
<%-- <h3>关于猫眼:</h3>--%>
<%-- <a href="">关于我们</a>|--%>
<%-- <a href="">管理团队</a>|--%>
<%-- <a href="">投资者关系</a>--%>
<%-- <h3>友情链接:</h3>--%>
<%-- <a href="">美团网</a>|--%>
<%-- <a href="">格瓦拉</a>|--%>
<%-- <a href="">美团下载</a>|--%>
<%-- <a href="">欢喜首映</a>--%>
<%-- </div>--%>
<%-- <p>--%>
<%-- 用户举报/涉未成年人有害信息举报邮箱:tousujubao@meituan.com 舞弊线索举报邮箱:wubijubao@maoyan.com--%>
<%-- </p>--%>
<%-- <p>--%>
<%-- 中华人民共和国增值电信业务经营许可证 京B2-20190350 | 营业性演出许可证 京演(机构)(2019)4094号--%>
<%-- </p>--%>
<%-- <p>广播电视节目制作经营许可证 (京)字第08478号 | 网络文化经营许可证 京网文(2019)3837-369号</p>--%>
<%-- <p>--%>
<%-- 猫眼用户服务协议 | 猫眼平台交易规则总则 | 隐私政策--%>
<%-- </p>--%>
<%-- <p>--%>
<%-- 京公网安备 11010102003232号 | 京ICP备16022489号-1--%>
<%-- </p>--%>
<%-- <p>--%>
<%-- 北京猫眼文化传媒有限公司--%>
<%-- </p>--%>
<%-- <p>--%>
<%-- ©2022 猫眼电影 www.maoyan.com--%>
<%-- </p>--%>
<%-- <a href=""><img src="images/foot1.png" alt=""></a>--%>
<%-- <a href=""><img src="images/foot2.png" alt=""></a>--%>
<%-- <a href=""><img src="images/foot3.png" alt=""></a>--%>
<%-- </div>--%>
<%--</div>--%>
</body>
</html>
movies类
package org.cuit.serviceProcess.model.info;
/**
* @version 1.0
* @Author 高拴梁
* @Date 2022/3/18 18:57
* @注释 电影类
*/
public class Movie {
/**
*
* @param adult 成人
* @param budget 预算
* @param genres 流派
* @param homepage 主页
* @param m_id 编码
* @param Imdb_id imdb编码
* @param original_language 初始语言
* @param overview 概述
* @param popularity 声望
* @param production_companies 发行公司
* @param release_date 发布时间
* @param revenue 收入
* @param runtime 运行
* @param spoken_languages 语言
* @param tagline 标题
* @param title 题目
* @param vote_average 平均投票
* @param vote_count 投票数
*/
private String adult;
private float budget;
private String genres;
private String homepage;
private int m_id;
private String Imdb_id;
private String original_language;
private String overview;
private String popularity;
private String production_companies;
private String release_date;
private float revenue;
private float runtime;
private String spoken_languages;
private String tagline;
private String title;
private float vote_average;
private float vote_count;
private String image_path;
@Override
public String toString() {
return "Movie{" +
"adult='" + adult + '\'' +
", budget=" + budget +
", genres='" + genres + '\'' +
", homepage='" + homepage + '\'' +
", m_id=" + m_id +
", Imdb_id='" + Imdb_id + '\'' +
", original_language='" + original_language + '\'' +
", overview='" + overview + '\'' +
", popularity='" + popularity + '\'' +
", production_companies='" + production_companies + '\'' +
", release_date='" + release_date + '\'' +
", revenue=" + revenue +
", runtime=" + runtime +
", spoken_languages='" + spoken_languages + '\'' +
", tagline='" + tagline + '\'' +
", title='" + title + '\'' +
", vote_average=" + vote_average +
", vote_count=" + vote_count +
", imagePath=" + image_path +
'}';
}
public String getImage_path() {
return image_path;
}
public void setImage_path(String image_path) {
this.image_path = image_path;
}
public Movie(String adult, float budget, String genres, String homepage, int m_id, String imdb_id, String original_language, String overview, String popularity, String production_companies, String release_date, float revenue, float runtime, String spoken_languages, String tagline, String title, float vote_average, float vote_count, String image_path) {
this.adult = adult;
this.budget = budget;
this.genres = genres;
this.homepage = homepage;
this.m_id = m_id;
Imdb_id = imdb_id;
this.original_language = original_language;
this.overview = overview;
this.popularity = popularity;
this.production_companies = production_companies;
this.release_date = release_date;
this.revenue = revenue;
this.runtime = runtime;
this.spoken_languages = spoken_languages;
this.tagline = tagline;
this.title = title;
this.vote_average = vote_average;
this.vote_count = vote_count;
this.image_path = image_path;
}
public String getAdult() {
return adult;
}
public void setAdult(String adult) {
this.adult = adult;
}
public float getBudget() {
return budget;
}
public void setBudget(float budget) {
this.budget = budget;
}
public String getGenres() {
return genres;
}
public void setGenres(String genres) {
this.genres = genres;
}
public String getHomepage() {
return homepage;
}
public void setHomepage(String homepage) {
this.homepage = homepage;
}
public int getM_id() {
return m_id;
}
public void setM_id(int m_id) {
this.m_id = m_id;
}
public String getImdb_id() {
return Imdb_id;
}
public void setImdb_id(String imdb_id) {
Imdb_id = imdb_id;
}
public String getOriginal_language() {
return original_language;
}
public void setOriginal_language(String original_language) {
this.original_language = original_language;
}
public String getOverview() {
return overview;
}
public void setOverview(String overview) {
this.overview = overview;
}
public String getPopularity() {
return popularity;
}
public void setPopularity(String popularity) {
this.popularity = popularity;
}
public String getProduction_companies() {
return production_companies;
}
public void setProduction_companies(String production_companies) {
this.production_companies = production_companies;
}
public String getRelease_date() {
return release_date;
}
public void setRelease_date(String release_date) {
this.release_date = release_date;
}
public float getRevenue() {
return revenue;
}
public void setRevenue(float revenue) {
this.revenue = revenue;
}
public float getRuntime() {
return runtime;
}
public void setRuntime(float runtime) {
this.runtime = runtime;
}
public String getSpoken_languages() {
return spoken_languages;
}
public void setSpoken_languages(String spoken_languages) {
this.spoken_languages = spoken_languages;
}
public String getTagline() {
return tagline;
}
public void setTagline(String tagline) {
this.tagline = tagline;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public float getVote_average() {
return vote_average;
}
public void setVote_average(float vote_average) {
this.vote_average = vote_average;
}
public float getVote_count() {
return vote_count;
}
public void setVote_count(float vote_count) {
this.vote_count = vote_count;
}
}