项目编号:BS-PT-106
一,环境介绍
语言环境:Java: jdk1.8
数据库:Mysql: mysql5.7
应用服务器:Tomcat: tomcat8.5.31
开发工具:IDEA或eclipse
开发技术:SSM框架+JSP+协同过滤算法+地图定位系统等
二,项目简介
信息技术的应用虽然说带来了很多的便宜,但同时也带了信息和数据的大爆炸。在信息匮乏的时代,人们期望获得更多的信息和数据,以便了解这个世界,但是真正到了数据大爆炸的时代,人们又往往无所适从,不知道怎么才能过滤掉那些对自己无用的数据,获得有效的信息。本次课题所研究的就是基于用户偏好来实抽电影推荐系统,其主要是根据用户在平台上的操作行为记录,来根据设定的相关规则判断用户的喜好,根据协同过滤算法来给用户进行相应的数据推荐。同时在用户无操作数据记录时,也就是常用的数据静默时,也根据相应的规则给用户推荐一些电影数据,以期为用户找到一些对自己有用的数据。
本系统主要基于Java开发技术平台来实现系统的开发,使用了SSM框架来完成电影推荐系统的后台服务接口开发和业务逻辑处理,使用JSP页面完成数据的展示,利用AJAX和JQUERY来实现人机交互的异步数据请求。具体的数据推荐主要使用协同过滤算法的数据模型进行数据推荐。系统整体功能完整,界面美观大方,人机交互效果好。
根据市场调研和用户走访,并进行整理分析,得知本次设计实现的电影推荐系统用户一共有二类,一是前端用户,一类是管理员用户。这二类用户的角色和操作功能权限各不不同,下面通过用例图的方式来进行展示。
前端用户的用例图如下图1所示。
图1 前端用户用例图
前端用户用例描述:前端用户注册登陆后,主要可以实现在线浏览新闻信息、分类浏览电影信息、电影影评信息、用户发布的电影攻略信息,查看推荐的电影信息,在线进行反馈留言,预定电影票等,同时在个人中心处可以发布电影攻略,查看个人的收藏信息、预定信息等。
管理员用户的操作用例图如下图2所示:
图2 管理员用户用例图
管理员用户用例图描述:管理员登陆电影推荐系统,主要的职责是对平台的基础信息进行管理,包含前端注册的用户信息管理、轮播图管理、资讯管理、电影管理、类型管理、电影说评管理、投诉管理、预定订单管理、攻略管理等。
在对整个电影推荐系统做了充分的需求分析和架构设计之后,最终确定了本次开发设计的电影推荐系统要实现的功能目标,下面分别展示一下电影推荐系统的前端用户功能架构和后台管理的功能架构图。前端用户的功能具体展示如下图3所示。
图3 前端用户功能结构图
前端用户的功能模块介绍:
(1)注册登录功能模块设计
前端用户进行相关操作时需要进行注册线上会员,填写个人账户信息和个人信息后注册成功后即可登陆。
(2)个人信息管理功能模块设计
用户登录系统后,可以进入系统管理来修改密码,输入旧密码、新密码并确认密码,保证新密码和确认密码一致的情况下则修改成功,如果不一致则就修改失败。
(3)信息浏览功能模块
前端用户可以在电影平台上浏览电影信息、相关电影说评信息、电影攻略信息、行业资讯信息等,可以查看具体各类信息的详情,并可以在线评论,对于喜欢的电影或电影说评,可以进行收藏。
(4)在线预定功能模块
前端用户登陆后,进入电影介绍的详情页面,可以点击预定按钮,在线预定电影,并可以在个人中心中管理自己预定的电影,待后台管理员审核通过后即算预定成功。
(5)电影攻略模块
用户可以在线进行发贴,书写自己所观看的电影的感受,或某个电影的攻略信息,并可以在线管理自己的贴子。
(6)个性化推荐模块
电影管理平台系统,会根据用户的浏览记录,进行相关的计算,采用协同过滤算法来给不同的用户进行相应的信息推荐,目前的数据模型主要是依据用户浏览的电影特点,匹配相关性的电影信息,在首页推荐模块进行推荐展示。
(7)全文检索模块
在电影管理平台系统中,前端用户可以根据相关的关键词来进行搜索,会全文匹配电影信息,电影说评信息等,根据标题说明来进行模糊匹配,将查找到的信息展现出来。
(8)投诉建议
除了提供用户的在线评论和收藏等互动功能外,还提供了投诉建议模块,以便用户及时反馈相关的意见,由后台管理员进行处理。
后端用户的功能模块介绍:
(1)个人信息管理:管理员登陆后台可以对个人的信息进行相应的管理操作。
(2)用户管理:管理员可以对前端注册的用户信息进行相应的管理操作。
(3)轮播图管理:对前端首页的轮播图信息进行相应的管理操作,可根据需求进行轮播图的更换等。
(4)行业资讯管理:主要管理和发布电影行业的相关动态新闻信息。
(5)电影管理:主要管理发布的电影信息,详细的介绍电影的价格,特点等,并在后台指定电影所放映的影院地图定位坐标,这使得前端用户可以直接通过百度地图定位电影院所在位置。
(6)电影说评管理:主要管理电影附近的相关电影说评信息,完成电影说评信息的增删改查操作。
(7)订单管理:主要管理前端用户的下单信息,前端会员预定电影后,需要管理员在后台进行审核,生效后方可使用。
(8)攻略管理:主要管理前端电影会员用户发布和电影攻略信息。
(9)投诉建议:对前端用户发布的投诉建议信息进行相关的管理操作。
三,系统展示
3.1前台功能模块的展示
3.1.1 注册登陆
电影推荐系统为前端用户提供了注册和登陆的基本功能,这也是为了确保用户进行在线预定等的数据安全和数据的对应,用户登陆的基本流程如下图3.1所示。
图3.1 登陆流程图
用户登陆的操作界面如下图5.2所示:
图3.2 用户登陆
登陆的前提是要有注册的账户信息,用户注册的基本流程如下图3.3所示:
图3.3 前端用户注册流程图
电影推荐系统的前端用户注册的界面如下图3.4所示:
图3.4 前端用户注册界面
3.1.2 电影分类浏览
用户登陆系统后可以在线查看发布的电影信息,平台提供了按电影名称进行全局搜索的操作,同时可以根据电影类型分类查询,具体展示如下图35所示。
图3.5 电影分类浏览
用户点击感兴趣的电影后会进入电影的详情界面,在电影的详情里可以查看这部电影相关具体的信息(导演、编剧、主演、简介等),还可以进行在线预定、收藏、评论留言等互动操作,具体如下图3.6所示。
图3.6 电影详情浏览
3.1.3 电影推荐
用户登陆系统后,系统可以根据用户的一些操作行为数据记录并基于系统所用的协同过滤算法功能来为用户推荐相关的电影信息并直接在系统的首页进行展示,具体展示如图3.7所示。
图3.7 电影推荐
3.1.4 行业新闻浏览
用户登陆系统后可以点击博客文章进入博客模块,用户可以在线查看用户发布的博客信息,具体展示如下图4.8所示。
图3.8 电影新闻浏览
3.1.5 观影攻略
用户登陆系统后可以点击电影攻略,查看每个用户分享的电影攻略信息,用户可以自己在平台发布每个电影观看的攻略详情,具体展示如下图3.9所示。
图3.9 电影攻略
3.1.6 电影说评
电影说评主要展示一些名人大伽对于电影的一些评析信息,用户在些模块可以进行查看,电影说评具体实现具体如下图3.10所示。
图3.10 个人信息管理
四,核心代码展示
package com.sys.controller.admin; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeSet; import javax.servlet.http.HttpServletRequest; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.sys.controller.MyController; import com.sys.controller.suanfa.Aprioti; import com.sys.controller.suanfa.Itemset; import com.sys.controller.xietong.XietongUtil; import com.sxl.util.RandomValidateCode; import com.sxl.util.StringHelper; @Controller("frontController") @RequestMapping(value = "/front") public class FrontController extends MyController { /** * 使用协同过滤算法进行相关推荐 * @param model * @param request * @return * @throws Exception */ @RequestMapping(value = "/index") public String frame(Model model, HttpServletRequest request) throws Exception { String sql = ""; sql = "select * from t_lbt"; List list3 = db.queryForList(sql); request.setAttribute("list3", list3); sql = "select a.* from t_product a where typesId=1 order by id desc limit 3"; List listb = db.queryForList(sql); request.setAttribute("listb", listb); //查询电影类型 sql = "select * from t_types"; model.addAttribute("typesList", db.queryForList(sql)); //协同过滤推荐算法 if(getCustomer(request)!=null){ //如果该用户登录了,身份确定了, 则可以用协同过滤推荐 List<Map> customerList = db.queryForList("select * from t_customer"); List<Map> dataList = db.queryForList("select distinct productId, customerId from t_productclick where productId is not null and customerId is not null "); int usersize = customerList.size(); String customerId = getCustomer(request).get("id").toString(); /** * 输入用户-->物品条目 一个用户对应多个物品 * 用户ID 物品ID集合 * A a b d * B a c * C b e * D c d e */ String[] userdata = new String[customerList.size()]; for (int i = 0; i < customerList.size(); i++) { String customerid = customerList.get(i).get("id").toString(); String aa="A"+customerid+""; for (int j = 0; j < dataList.size(); j++) { if(customerid.equals(dataList.get(j).get("customerId").toString())){ aa+="@"+dataList.get(j).get("productId").toString(); } } userdata[i]= aa+="@0"; System.out.println("******"+aa); } String out = XietongUtil.xietongjob(usersize, userdata, "A"+customerId); String sqlall="select a.* from t_product a where typesId=1 "; sql=sqlall; if(out!=null&&!"".equals(out)){ sql+=" and id in ("+out.substring(1,out.length())+")"; } sql+=" order by rand() limit 8 "; //以上推荐算法最总结果在根据随机安排推荐 //注!为了应对一开始人员访问数据量不够推荐算法使用的情况,就进行了数据补足,这个业务逻辑就非常完美了。 List tuijianList = db.queryForList(sql); int a = 8; int b = 0; if(tuijianList==null||tuijianList.size()<8){ if(tuijianList!=null){ b = 8-tuijianList.size(); } List list2 = db.queryForList(sqlall+" order by rand() limit "+b); tuijianList.addAll(list2); }else{ } request.setAttribute("tuijianList", tuijianList); }else{ //也就是说,如果网站用户未登录,则不能身份确认,所以用aprio算法 //aprio推荐算法 tuijiansuanfa(request); } return "/front/index"; } /** * 专门有个算法包 * 然后算法的逻辑也在这里, * 而且把算法之外额逻辑也加了 * 注!为了应对一开始人员访问数据量不够推荐算法使用的情况,就进行了数据补足,这个业务逻辑就非常完美了。 * * java推荐算法 * @param request */ public void tuijiansuanfa(HttpServletRequest request){ Itemset originalItem = new Itemset(); List<Map> lista = db.queryForList("select * from t_customer"); for (int i = 0; i < lista.size(); i++) { TreeSet<String> itemset = new TreeSet<String>(); List<Map> listb = db.queryForList("select * from t_productclick where customerId=?",new Object[]{lista.get(i).get("id")}); for (int j = 0; j < listb.size(); j++) { itemset.add(listb.get(j).get("productId")+""); } originalItem.itemset.add(itemset); } Aprioti.originalItem=originalItem; List<Long> outList = Aprioti.aprioriProcess(); String in =""; if(outList!=null&&outList.size()>0){ for (int i = 0; i < outList.size(); i++) { in+=","+outList.get(i); } } String sqlall="select a.* from t_product a where 1=1 "; String sql=sqlall; if(in!=null&&!"".equals(in)){ sql+=" and id in ("+in.substring(1,in.length())+")"; } sql+=" order by rand() limit 8 "; //以上推荐算法最总结果在根据随机安排推荐 //注!为了应对一开始人员访问数据量不够推荐算法使用的情况,就进行了数据补足,这个业务逻辑就非常完美了。 List tuijianList = db.queryForList(sql); int a = 8; int b = 0; if(tuijianList==null||tuijianList.size()<8){ if(tuijianList!=null){ b = 8-tuijianList.size(); } List list2 = db.queryForList(sqlall+" order by rand() limit "+b); tuijianList.addAll(list2); }else{ } request.setAttribute("tuijianList", tuijianList); } @RequestMapping(value = "/baidu1") public String baidu1(Model model, HttpServletRequest request) throws Exception { return "/front/baidu1"; } @RequestMapping(value = "/baidu2") public String baidu2(Model model, HttpServletRequest request) throws Exception { return "/front/baidu2"; } @RequestMapping(value = "/daohang1") public String daohang1(Model model, HttpServletRequest request,String id) throws Exception { Map map = db.queryForMap("select * from t_product where id="+id); model.addAttribute("map", map); return "/front/daohang1"; } public String getjwd(HttpServletRequest request){ Object jwdd= request.getSession().getAttribute("yhjwd"); if(jwdd!=null){ return jwdd.toString(); }else{ return "116.438189,39.9125"; } } @RequestMapping(value = "/daohang2") public String daohang2(Model model, HttpServletRequest request,String id) throws Exception { Map map = db.queryForMap("select *from t_zx where id="+id); map = new HashMap(); map.put("jwd", "116.661256,39.975119"); model.addAttribute("map", map); String jwd = getjwd(request); System.out.println(jwd); System.out.println(map.get("jwd")); model.addAttribute("jwd", jwd); return "/front/daohang2"; } @RequestMapping(value = "/login") public String login(Model model, HttpServletRequest request) throws Exception { return "/front/login"; } public void saveClick(HttpServletRequest request,Long id){ String sql="insert into t_productclick(productId,customerId,insertDate) values(?,?,now())"; Map customer = getCustomer(request); if(customer!=null&&customer.size()>0){ db.update(sql, new Object[]{id,getCustomer(request).get("id")}); } } /** * 查询信息 * @param model * @param request * @param typesId * @param productName * @param px * @return * @throws Exception */ @RequestMapping(value = "/all") public String all(Model model, HttpServletRequest request,Long typesId,String productName,String px,Integer bqid) throws Exception { String sql="select a.* from t_types a where 1=1"; sql+=" order by id desc"; List typesList = db.queryForList(sql); request.setAttribute("typesList", typesList); sql="select a.*,(select typesName from t_types b where a.typesId=b.id) typesName from t_product a where 1=1"; if(typesId!=null&&!"".equals(typesId)){ sql+=" and a.typesId="+typesId; } if(productName!=null&&!"".equals(productName)){ sql+=" and a.productName like '%"+productName+"%' "; } if(bqid!=null){ sql+=" and bqid="+bqid; } if("1".equals(px)){ sql+=" order by id desc"; }else if("2".equals(px)){ sql+=" order by price asc"; }else if("3".equals(px)){ sql+=" order by price desc"; }else if("4".equals(px)){ sql+=" order by djl desc"; } List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/all"; } @RequestMapping(value = "/jfdh") public String jfdh(Model model, HttpServletRequest request) throws Exception { String sql="select a.* from t_jfdh a where 1=1"; sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/jfdh"; } @RequestMapping(value = "/dhjfSave") public ResponseEntity<String> dhjfSave(Model model, HttpServletRequest request,Long id) throws Exception { Map map = db.queryForMap("select * from t_jfdh where id="+id); String jf = map.get("jfCost").toString(); String jfName = map.get("jfName").toString(); //订单 String sql = "insert into t_order(orderNum,customerId,productDetail,allPrice,status,insertDate) values(?,?,?,?,?,now())"; int result = db.update(sql, new Object[] { System.currentTimeMillis()+"", getCustomer(request).get("id").toString(), jfName+"积分兑换["+jf+"]", 0+"", "兑换完成" }); sql="update t_customer set jf = jf-"+jf+" where id="+getCustomer(request).get("id"); db.update(sql); //积分减少 return renderData(true, "操作成功", null); } @RequestMapping(value = "/register") public String register(Model model, HttpServletRequest request) throws Exception { System.out.println("112312312"); return "/front/register"; } @RequestMapping(value = "/detail") public String detail(Model model, HttpServletRequest request, Long id) throws Exception { //保存点击 saveClick(request, id); String sql = "select a.*,(select typesName from t_types b where a.typesId=b.id) typesName " + " from t_product a where id=" + id; Map map = db.queryForMap(sql); request.setAttribute("map", map); String sql2="select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName from t_pinglun_product a where productId=? order by id desc"; List<Map> list = db.queryForList(sql2,new Object[]{id}); model.addAttribute("list", list); db.update("update t_product set djl=djl+1 where id="+id); int scNum = db.queryForInt("select count(1) from t_sc where productId="+id); model.addAttribute("scNum", scNum); return "/front/detail"; } @RequestMapping(value = "/myOrder") public String myOrder(Model model, HttpServletRequest request) throws Exception { String sql = "select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName from t_order a where 1=1 "; if (1 == 1) { sql += "and customerId=" + getCustomer(request).get("id") + " "; } sql += " order by id desc"; List list = db.queryForList(sql); request.setAttribute("orderList", list); return "/front/myOrder"; } @RequestMapping(value = "/deleteOneOrder") public ResponseEntity<String> deleteOneOrder(Model model, HttpServletRequest request,Long id) throws Exception { String sql="delete from t_order where id="+id; db.update(sql); return renderData(true, "操作成功", null); } @RequestMapping(value = "/pjSave") public ResponseEntity<String> pjSave(Model model, HttpServletRequest request,Long id,String pj) throws Exception { String sql="update t_order set pj='"+pj+"' where id="+id; db.update(sql); return renderData(true, "操作成功", null); } @RequestMapping(value = "/deletesc") public ResponseEntity<String> deletesc(Model model, HttpServletRequest request,Long id) throws Exception { String sql="delete from t_sc where id="+id; db.update(sql); return renderData(true, "操作成功", null); } @RequestMapping(value = "/deletexiaoxi") public ResponseEntity<String> deletexiaoxi(Model model, HttpServletRequest request,Long id) throws Exception { String sql="delete from t_xiaoxi where id="+id; db.update(sql); return renderData(true, "操作成功", null); } @RequestMapping(value = "/addShopcar") public ResponseEntity<String> addShopcar(Model model, HttpServletRequest request, Long id, Integer num) throws Exception { int result = 0; db.update("delete from t_shopcar where customerId="+getCustomer(request).get("id")); String sql = "insert into t_shopcar(productId,num,customerId) values(?,?,?)"; result = db.update(sql, new Object[] { id, 1, getCustomer(request).get("id").toString() }); return renderData(true, "操作成功", null); } @RequestMapping(value = "/pay3") public ResponseEntity<String> pay3(Model model, HttpServletRequest request,Long address) throws Exception { String sql = "select a.*,(select productName from t_product b where a.productId=b.id) productName," + "(select price from t_product b where a.productId=b.id) price,(select jf from t_product b where a.productId=b.id) jf from t_shopcar a where customerId=" + getCustomer(request).get("id"); sql += " order by id desc"; List<Map> list = db.queryForList(sql); int total = 0; int jf = 0; String productDetail = ""; String productId=""; for (int i = 0; i < list.size(); i++) { productId = list.get(i).get("productId").toString(); productDetail += "," + list.get(i).get("productName") + "[" + list.get(i).get("num") + "]"; total += Integer.parseInt(list.get(i).get("price").toString()) * Integer.parseInt(list.get(i).get("num").toString()); // jf+=Integer.parseInt(list.get(i).get("jf").toString()) // * Integer.parseInt(list.get(i).get("num").toString()); String sql2="update t_product set nums=nums-"+list.get(i).get("num").toString()+" where id="+list.get(i).get("productId").toString(); db.update(sql2); } Map addressMap = db.queryForMap("select * from t_address where id=?",new Object[]{address}); sql = "insert into t_order(orderNum,customerId,productDetail,allPrice,status,insertDate,lxr,lxfs,address,productId) values(?,?,?,?,?,now(),?,?,?,?)"; int result = db.update(sql, new Object[] { System.currentTimeMillis()+"", getCustomer(request).get("id").toString(), productDetail.subSequence(1, productDetail.length()), total+"", "等待处理",addressMap.get("lxr"),addressMap.get("phone"),addressMap.get("xxdz"),productId }); sql = "delete from t_shopcar where customerId=" + getCustomer(request).get("id"); db.update(sql); if (result == 1) { return renderData(true, "操作成功", null); } else { return renderData(false, "操作失败", null); } } // @RequestMapping(value = "/addShopcar") // public ResponseEntity<String> addShopcar(Model model, // HttpServletRequest request, Long id, Integer num) throws Exception { // int result = 0; // // 判断该用户是否 // String sql = "select * from t_shopcar where productId=? and customerId=?"; // Map map = db.queryForMap(sql, new Object[] { id.toString(), // getCustomer(request).get("id").toString() }); // if (map != null && map.size() > 0) { // sql = "update t_shopcar set productId=?,num=num+" + num // + " where id=?"; // result = db.update(sql, new Object[] { id, map.get("id") }); // } else { // sql = "insert into t_shopcar(productId,num,customerId) values(?,?,?)"; // result = db.update(sql, new Object[] { id, num, // getCustomer(request).get("id").toString() }); // } // if (result == 1) { // return renderData(true, "操作成功", null); // } else { // return renderData(false, "操作失败", null); // } // } @RequestMapping(value = "/checkIsLogin") public ResponseEntity<String> checkIsLogin(Model model, HttpServletRequest request) throws Exception { Map customer = getCustomer(request); if (customer != null && customer.size() > 0) { return renderData(true, "操作成功", null); } else { return renderData(false, "操作失败", null); } } @RequestMapping(value = "/pay") public ResponseEntity<String> pay(Model model, HttpServletRequest request,Long address) throws Exception { String orderDate = request.getParameter("orderDate"); String zffs = request.getParameter("zffs"); String sql = "select a.*,(select productName from t_product b where a.productId=b.id) productName," + "(select price from t_product b where a.productId=b.id) price,(select jf from t_product b where a.productId=b.id) jf from t_shopcar a where customerId=" + getCustomer(request).get("id"); sql += " order by id desc"; List<Map> list = db.queryForList(sql); int total = 0; int jf = 0; String productDetail = ""; String productId=""; for (int i = 0; i < list.size(); i++) { productId = list.get(i).get("productId").toString(); productDetail = list.get(i).get("productName").toString() ; sql = "insert into t_order(orderNum,customerId,productDetail,allPrice,status,insertDate,lxr,lxfs,address,productId,orderDate,zffs) values(?,?,?,?,?,now(),?,?,?,?,?,?)"; db.update(sql, new Object[] { System.currentTimeMillis()+"", getCustomer(request).get("id").toString(), productDetail, list.get(i).get("price").toString()+"", "等待处理",null,null,null,productId ,orderDate,zffs}); } sql = "delete from t_shopcar where customerId=" + getCustomer(request).get("id"); db.update(sql); return renderData(true, "操作成功", null); } @RequestMapping(value = "/shopcar") public String shopcar(Model model, HttpServletRequest request) throws Exception { Map customer = getCustomer(request); if (customer != null && customer.size() > 0) { } else { return "redirect:/front/register.html"; } String sql="select a.* from t_address a where 1=1"; if(1==1){sql+=" and customerId="+getCustomer(request).get("id") +" ";} sql+=" order by id desc"; List addressList = db.queryForList(sql); request.setAttribute("addressList", addressList); sql = "select b.*,a.id ids,a.num num from t_shopcar a left join t_product b on a.productId=b.id where 1=1 and customerId=" + getCustomer(request).get("id"); sql += " order by id desc"; System.out.println(sql); List<Map> list = db.queryForList(sql); request.setAttribute("list", list); System.out.println(list); int total = 0; if(list!=null&&list.size()>0){ for (int i = 0; i < list.size(); i++) { total += Integer.parseInt(list.get(i).get("price").toString()) * Integer.parseInt(list.get(i).get("num").toString()); } } request.setAttribute("total", total); return "/front/shopcar"; } @RequestMapping(value = "/save") public ResponseEntity<String> loginSave(Model model, HttpServletRequest request, String username, String password) throws Exception { String sql = "select * from t_customer where username=?"; List<Map> list = db.queryForList(sql, new Object[] { username }); String result = "1"; if (list != null && list.size() > 0) { Map map = list.get(0); if (StringHelper.get(map, "password").equals(password)) { request.getSession().setMaxInactiveInterval(60 * 60 * 24); request.getSession().setAttribute("customerBean", map); result = "1"; } else { result = "0"; } } else { result = "0"; } return renderData(true, result, null); } @RequestMapping(value = "/deleteOneShopCar") public ResponseEntity<String> deleteOneShopCar(Model model, HttpServletRequest request,Long id) throws Exception { String sql="delete from t_shopcar where id="+id; db.update(sql); return renderData(true, "", null); } @RequestMapping(value = "/updateShopCar") public ResponseEntity<String> updateShopCar(Model model, HttpServletRequest request,Long id,Integer num) throws Exception { String sql="update t_shopcar set num="+num+" where id="+id; System.out.println(sql); db.update(sql); return renderData(true, "", null); } @RequestMapping(value = "/registerSave") public ResponseEntity<String> registerSave(Model model, HttpServletRequest request, Long id, String username, String password, String customerName, String sex, String address,String headPic, String phone) throws Exception { String yzm = request.getParameter("yzm"); String yzmnow = request.getSession().getAttribute(RandomValidateCode.RANDOMCODEKEY).toString().toUpperCase(); if(!yzmnow.equals(yzm.toUpperCase())){ return renderData(false, "5", null); } int a = db.queryForInt("select count(1) from t_customer where username=?",new Object[]{username}); if(a>0){ return renderData(false, "1", null); } int result = 0; if(headPic==null||"".equals(headPic)){ headPic ="resource/front4/123.jpg"; } String sql = "insert into t_customer(username,password,customerName,sex,address,phone,headPic) values(?,?,?,?,?,?,?)"; result = db.update(sql, new Object[] { username, password, customerName, sex, address, phone,headPic }); sql = "select * from t_customer order by id desc limit 1"; List<Map> list = db.queryForList(sql); request.getSession().setMaxInactiveInterval(60 * 60 * 24); request.getSession().setAttribute("customerBean", list.get(0)); return renderData(true, "操作成功", null); } @RequestMapping(value = "/out") public String out(Model model, HttpServletRequest request) throws Exception { request.getSession().removeAttribute("customerBean"); return "redirect:/front/login.html"; } @RequestMapping(value = "/mine") public String mine(Model model, HttpServletRequest request) throws Exception { Map customer = getCustomer(request); Map map = db.queryForMap("select * from t_customer where id=?", new Object[] { customer.get("id") }); model.addAttribute("customer", map); return "/front/mine"; } @RequestMapping(value = "/mineSave") public ResponseEntity<String> mineSave(Model model, HttpServletRequest request, Long id, String username, String password, String customerName, String sex, String address,String headPic, String phone) throws Exception { int result = 0; String sql = "update t_customer set customerName=?,sex=?,address=?,phone=?,headPic=? where id=?"; result = db.update(sql, new Object[] { customerName, sex, address, phone,headPic, id }); sql = "select * from t_customer where id="+id; List<Map> list = db.queryForList(sql); request.getSession().setMaxInactiveInterval(60 * 60 * 24); request.getSession().setAttribute("customerBean", list.get(0)); return renderData(true, "操作成功", null); } @RequestMapping(value = "/password") public String password(Model model, HttpServletRequest request) throws Exception { return "/front/password"; } @RequestMapping(value = "/changePassword") public ResponseEntity<String> changePassword(Model model, HttpServletRequest request, String oldPassword, String newPassword) throws Exception { Map customer = getCustomer(request); if (oldPassword.equals(customer.get("password").toString())) { String sql = "update t_customer set password=? where id=?"; db.update(sql, new Object[] { newPassword, customer.get("id") }); return renderData(true, "1", null); } else { return renderData(false, "1", null); } } @RequestMapping(value = "/scSave") public ResponseEntity<String> scSave(Model model, HttpServletRequest request, Long id, String pl) throws Exception { int result = 0; String customerId = getCustomer(request).get("id").toString(); db.update("delete from t_sc where productId=? and customerId=? ", new Object[] {id,customerId }); String sql = "insert into t_sc(productId,customerId,insertDate) values(?,?,now())"; result = db.update(sql, new Object[] {id,customerId }); return renderData(true, "操作成功", null); } @RequestMapping(value = "/plSave") public ResponseEntity<String> plSave(Model model, HttpServletRequest request, Long id, String pl) throws Exception { int result = 0; String sql = "update t_order set pl=? where id=?"; result = db.update(sql, new Object[] { pl, id }); if (result == 1) { return renderData(true, "操作成功", null); } else { return renderData(false, "操作失败", null); } } @RequestMapping(value = "/contact") public String fk(Model model, HttpServletRequest request) throws Exception { return "/front/contact"; } @RequestMapping(value = "/contactSave") public ResponseEntity<String> contactSave(Model model, HttpServletRequest request, String content, String phone) throws Exception { int result = 0; String sql = "insert into t_contact(customerId,phone,content,insertDate) values(?,?,?,now())"; result = db.update(sql, new Object[] { getCustomer(request).get("id"), phone, content }); if (result == 1) { return renderData(true, "操作成功", null); } else { return renderData(false, "操作失败", null); } } @RequestMapping(value = "/message") public String message(Model model, HttpServletRequest request) throws Exception { String sql = "select a.*,(select max(name) from t_customer b where a.customerId=b.id) customerName from t_message a where 1=1 "; sql += " and customerId=" + getCustomer(request).get("id") + " "; sql += " order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); System.out.println(list); return "/front/message"; } @RequestMapping(value = "/saveMessageContent") public ResponseEntity<String> saveMessageContent(Model model, HttpServletRequest request, String messageContent) throws Exception { Map customer = getCustomer(request); String sql = "insert into t_message(customerId,messageContent,insertDate,types) values(?,?,now(),1)";//1代表我 int result = db .update(sql, new Object[] { getCustomer(request).get("id"), messageContent }); return renderData(true, "1", null); } ///前端增删改查例子开始// @RequestMapping(value = "/test") public String test(Model model, HttpServletRequest request,String flag,String testName)throws Exception { String sql="select a.*,(select max(name) from t_customer b where a.customerId=b.id) customerName from t_test a where 1=1"; if(testName!=null&&!"".equals(testName)){ sql+=" and testName like '%"+testName+"%' "; } sql+=" and customerId="+getCustomer(request).get("id"); sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/test"; } @RequestMapping(value = "/testaddSave") public ResponseEntity<String> testaddSave(Model model,HttpServletRequest request,Long id,String flag ,Integer customerId,String testName,String testContent,String testSex,String testDay,String testPic,String insertDate) throws Exception{ int result = 0; if(id!=null){ String sql="update t_test set testName=?,testContent=?,testSex=?,testDay=?,testPic=? where id=?"; result = db.update(sql, new Object[]{testName,testContent,testSex,testDay,testPic,id}); }else{ String sql="insert into t_test(customerId,testName,testContent,testSex,testDay,testPic,insertDate) values(?,?,?,?,?,?,now())"; result = db.update(sql, new Object[]{getCustomer(request).get("id"),testName,testContent,testSex,testDay,testPic}); } if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/testDelete") public ResponseEntity<String> testDelete(Model model,HttpServletRequest request,Long id,String flag) throws Exception { String sql="delete from t_test where id=?"; int result = db.update(sql, new Object[]{id}); if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/testadd") public String testadd(Model model, HttpServletRequest request,Long id,String flag)throws Exception { if(id!=null){ //修改 String sql="select * from t_test where id=?"; Map map = db.queryForMap(sql,new Object[]{id}); model.addAttribute("map", map); }String sql=""; return "/front/testadd"; } ///前端增删改查例子结束/ @RequestMapping(value = "/find") public String find(Model model, HttpServletRequest request) throws Exception { return "/front/find"; } @RequestMapping(value = "/findSave") public ResponseEntity<String> findSave(Model model, HttpServletRequest request, String username, String phone) throws Exception { String sql = "select * from t_customer where username=? and phone=?"; List<Map> list = db.queryForList(sql, new Object[] { username,phone }); System.out.println(list); String result = "1"; if (list != null && list.size() > 0) { Map map = list.get(0); return renderData(true, result, null); } else { return renderData(false, result, null); } } @RequestMapping(value = "/findSaveConfirm") public ResponseEntity<String> findSaveConfirm(Model model, HttpServletRequest request, String username, String phone,String password) throws Exception { String sql = "update t_customer set password=? where username=? and phone=?"; db.update(sql, new Object[] {password, username,phone }); return renderData(true, "", null); } @RequestMapping(value = "/lt") public String lt(Model model, HttpServletRequest request,String searchName,Long oneClassifyId) throws Exception { Map customer = getCustomer(request); String sql="select a.*,(select max(customerName) from t_customer b where b.id=a.customerId) customerName," + "(select count(1) from t_pinglun b where b.wdxxId=a.id) nums from t_wdxx a where 1=1 "; if(searchName !=null&&!"".equals(searchName)){ sql+=" and a.title like '%"+searchName+"%'"; } if(customer==null||customer.size()==0){ sql+=" and a.nologin='是' "; } sql+=" order by id desc"; List<Map> list = db.queryForList(sql); model.addAttribute("list", list); return "/front/lt"; } @RequestMapping(value = "/wdxxList") public String wdxxList(Model model, HttpServletRequest request,String flag,String title)throws Exception { String sql="select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName from t_wdxx a where 1=1"; if(1==1){sql+=" and customerId="+getCustomer(request).get("id") +" ";} if(title!=null&&!"".equals(title)){ sql+=" and title like '%"+title+"%'"; } sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/wdxxList"; } @RequestMapping(value = "/mineaddress") public String mineaddress(Model model, HttpServletRequest request,String flag,String title)throws Exception { String sql="select a.* from t_address a where 1=1"; if(1==1){sql+=" and customerId="+getCustomer(request).get("id") +" ";} sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/mineaddress"; } @RequestMapping(value = "/minesc") public String minesc(Model model, HttpServletRequest request,String flag,String title)throws Exception { String sql="select (select max(productName) from t_product b where b.id=a.productId) productName,(select max(productPic1) from t_product b where b.id=a.productId) productPic1,id,productId from t_sc a where 1=1"; if(1==1){sql+=" and customerId="+getCustomer(request).get("id") +" ";} sql+=" order by id desc"; List list = db.queryForList(sql); System.out.println(sql); request.setAttribute("list", list); return "/front/minesc"; } @RequestMapping(value = "/minexiaoxi") public String minexiaoxi(Model model, HttpServletRequest request,String flag,String title)throws Exception { String sql=" select * from t_xiaoxi a where 1=1"; if(1==1){sql+=" and customerId="+getCustomer(request).get("id") +" ";} sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/minexiaoxi"; } @RequestMapping(value = "/hywdxxList") public String hywdxxList(Model model, HttpServletRequest request,String flag,String title)throws Exception { Map customer = getCustomer(request); String sql="select a.*,(select max(name) from t_customer b where a.customerId=b.id) customerName from t_wdxx a where 1=1"; sql+=" and exists(select 1 from t_wdhy b where a.customerId=b.hhId and b.customerId="+customer.get("id")+") "; if(title!=null&&!"".equals(title)){ sql+=" and title like '%"+title+"%'"; } sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/wdxxList"; } @RequestMapping(value = "/wdxxEditSave") public ResponseEntity<String> editSave(Model model,HttpServletRequest request,Long id,String flag ,Integer customerId,String title,String pic,String content,Integer zan,String insertDate,String nologin,Long bkId) throws Exception{ int result = 0; if(id!=null){ String sql="update t_wdxx set title=?,pic=?,content=?,nologin=?,bkId=? where id=?"; result = db.update(sql, new Object[]{title,pic,content,nologin,bkId,id}); }else{ String sql="insert into t_wdxx(customerId,title,pic,content,zan,insertDate,nologin,bkId) values(?,?,?,?,?,now(),?,?)"; result = db.update(sql, new Object[]{getCustomer(request).get("id"),title,pic,content,0,nologin,bkId}); } if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/mineaddressEditSave") public ResponseEntity<String> mineaddressEditSave(Model model,HttpServletRequest request,Long id,String province,String city,String area,String phone,String lxr,String xxdz) throws Exception{ int result = 0; if(id!=null){ String sql="update t_address set province=?,city=?,area=?,phone=?,lxr=?,xxdz=? where id=?"; result = db.update(sql, new Object[]{province,city,area,phone,lxr,xxdz,id}); }else{ String sql="insert into t_address(customerId,province,city,area,phone,lxr,xxdz) values(?,?,?,?,?,?,?)"; result = db.update(sql, new Object[]{getCustomer(request).get("id"),province,city,area,phone,lxr,xxdz}); } if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/wdxxEditDelete") public ResponseEntity<String> editDelete(Model model,HttpServletRequest request,Long id,String flag) throws Exception { String sql="delete from t_wdxx where id=?"; int result = db.update(sql, new Object[]{id}); if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/wdxxEdit") public String wdxxEdit(Model model, HttpServletRequest request,Long id,String flag)throws Exception { if(id!=null){ //修改 String sql="select * from t_wdxx where id=?"; Map map = db.queryForMap(sql,new Object[]{id}); model.addAttribute("map", map); }String sql=""; return "/front/wdxxEdit"; } @RequestMapping(value = "/mineaddressEdit") public String mineaddressEdit(Model model, HttpServletRequest request,Long id,String flag)throws Exception { if(id!=null){ //修改 String sql="select * from t_address where id=?"; Map map = db.queryForMap(sql,new Object[]{id}); model.addAttribute("map", map); }String sql=""; return "/front/mineaddressEdit"; } @RequestMapping(value = "/wdxxShow") public String wdxxShow(Model model, HttpServletRequest request,Long id,String flag)throws Exception { if(id!=null){ //修改 String sql="select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName,(select count(1) from t_pinglun b where b.wdxxId=a.id) nums from t_wdxx a where id=?"; Map map = db.queryForMap(sql,new Object[]{id}); model.addAttribute("map", map); } String sql="select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName,(select max(headPic) from t_customer b where a.customerId=b.id) headPic from t_pinglun a where wdxxId=? order by id desc"; List<Map> list = db.queryForList(sql,new Object[]{id}); model.addAttribute("list", list); sql="select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName from t_wdxx a where 1=1 order by zan desc limit 4"; List list3 = db.queryForList(sql); request.setAttribute("list3", list3); sql="select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName from t_wdxx a where 1=1 order by id desc limit 4"; List list4 = db.queryForList(sql); request.setAttribute("list4", list4); return "/front/wdxxShow"; } @RequestMapping(value = "/wdxxDelete") public ResponseEntity<String> wdxxDelete(Model model, HttpServletRequest request, Long id) throws Exception { Map customer = getCustomer(request); String sql="delete from t_wdxx where id=?"; db.update(sql, new Object[]{id}); return renderData(true, "操作成功", null); } @RequestMapping(value = "/addressDelete") public ResponseEntity<String> addressDelete(Model model, HttpServletRequest request, Long id) throws Exception { Map customer = getCustomer(request); String sql="delete from t_address where id=?"; db.update(sql, new Object[]{id}); return renderData(true, "操作成功", null); } @RequestMapping(value = "/pinglunSave") public ResponseEntity<String> pinglunSave(Model model,HttpServletRequest request,Long id,String flag ,String wdxxId,Integer customerId,String content,String insertDate) throws Exception{ int result = 0; String sql="insert into t_pinglun(wdxxId,customerId,content,insertDate) values(?,?,?,now())"; result = db.update(sql, new Object[]{wdxxId,getCustomer(request).get("id"),content}); if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/productPinglunSave") public ResponseEntity<String> productPinglunSave(Model model,HttpServletRequest request,Long id,String flag ,String productId,Integer customerId,String content,String insertDate) throws Exception{ int result = 0; String sql="insert into t_pinglun_product(productId,customerId,content,insertDate) values(?,?,?,now())"; result = db.update(sql, new Object[]{productId,getCustomer(request).get("id"),content}); if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/zanSave") public ResponseEntity<String> zanSave(Model model,HttpServletRequest request,Long id) throws Exception{ int result = 0; String sql="update t_wdxx set zan=zan+1 where id=?"; result = db.update(sql, new Object[]{id}); if(result==1){ return renderData(true,"操作成功",null); }else{ return renderData(false,"操作失败",null); } } @RequestMapping(value = "/zxList") public String zxList(Model model, HttpServletRequest request,String flag,String title)throws Exception { String sql="select a.* from t_zx a where 1=1 "; if(title!=null&&!"".equals(title)){ sql+=" and title like '%"+title+"%'"; } sql+=" order by id desc"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/zxList"; } @RequestMapping(value = "/zxShow") public String zxShow(Model model, HttpServletRequest request,Long id,String flag)throws Exception { String sql="select * from t_zx where id=?"; Map map = db.queryForMap(sql,new Object[]{id}); model.addAttribute("map", map); sql="select a.* from t_zx a where 1=1 "; sql+=" order by id desc limit 3"; List list = db.queryForList(sql); request.setAttribute("list", list); return "/front/zxShow"; } @RequestMapping(value = "/ltjlDelete") public ResponseEntity<String> ltjlDelete(Model model,HttpServletRequest request,Long id,String pl,String flag) throws Exception { System.out.println("getCustomer(request).get()==================="+getCustomer(request).get("id")); db.update("delete from t_liaotian where customerId=? or toId=?", new Object[]{getCustomer(request).get("id"),getCustomer(request).get("id")}); return renderData(true,"操作成功",null); } @RequestMapping(value = "/liaotian") public String liaotian(Model model, HttpServletRequest request,Long id,String flag,Long toId)throws Exception { Map customer = getCustomer(request); if (customer != null && customer.size() > 0) { } else { return "redirect:/front/register.html"; } String customerId = getCustomer(request).get("id").toString(); String batchNum1 = customerId+"&&"+toId; String batchNum2 = toId+"&&"+customerId; List list = db.queryForList("select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName1," + "(select max(name) from t_user c where a.toId=c.id) customerName2 from t_liaotian a where batchNum in ('"+batchNum1+"','"+batchNum2+"') order by id asc"); System.out.println("select a.*,(select max(customerName) from t_customer b where a.customerId=b.id) customerName1," + "(select max(name) from t_user c where a.toId=c.id) customerName2 from t_liaotian a where batchNum in ('"+batchNum1+"','"+batchNum2+"') order by id asc"); model.addAttribute("list", list); System.out.println(list); return "/front/liaotian"; } @RequestMapping(value = "/woxiaoxi") public String woxiaoxi(Model model, HttpServletRequest request,Long id,String flag,Long toId)throws Exception { String customerId = getCustomer(request).get("id").toString(); String sql="select customerId,(select max(customerName) from t_customer b where b.id=a.customerId) customerName from t_liaotian a where toId="+customerId+" group by customerId "; System.out.println(db.queryForList(sql)); model.addAttribute("list", db.queryForList(sql)); return "/front/woxiaoxi"; } @RequestMapping(value = "/liaotianSave") public ResponseEntity<String> liaotianSave(Model model,HttpServletRequest request,Long toId,String content) throws Exception { String customerId = getCustomer(request).get("id").toString(); String batchNum = customerId+"&&"+toId; db.update("insert into t_liaotian(customerId,toId,content,insertDate,batchNum,fq) values(?,?,?,now(),?,1)", new Object[]{customerId,toId,content,batchNum}); return renderData(true,"操作成功",null); } }
五,项目总结
本课题主要实现基于用户偏好实现的电影信息推荐系统,根据相关分析,本系统主要实现前端用户和后台管理用户两类角色的相关操作功能,具体实现了电影信息的在线浏览、收藏、评论和预定功能,同时根据用户的操作记录,完成电影信息的数据推荐功能。主要有以下几个章节组成。
第一部分主要是通过绪论来阐述开发这个推荐系统的基本背景及其意义,之后描述了推荐系统在国内外不同的研究情况和协同过滤算法应用的相关介绍以及其现状。
第二部分详细介绍了本系统使用的SSM框架,以及系统的整体架构模型和所使用的数据库类型。
第三部分主要通过多方位全面的对系统进行了需求分析,论证了系统技术和操作的可行性以及系统所需要的功能点和非功能性需求。
第四部分主要基于系统的需求来设计系统的整体架构和功能架构以及业务逻辑,细化到了每个小模块的设计,同时也说明了系统的数据库设计与实现。
第五部分主要根据上一部分的系统设计,实现了系统的各个功能模块并进行了前端页面的演示。
第六部分测试主要通过明确测试的目的与方法来搭建测试环境以及测试用例的编写完成对系统的功能性测试。