{"id":5319,"date":"2022-02-17T15:31:12","date_gmt":"2022-02-17T07:31:12","guid":{"rendered":"https:\/\/www.xttblog.com\/?p=5319"},"modified":"2022-02-17T15:31:12","modified_gmt":"2022-02-17T07:31:12","slug":"java%e7%89%88%e5%8d%8f%e5%90%8c%e8%bf%87%e6%bb%a4%e7%ae%97%e6%b3%95%e7%bb%88%e6%9e%81%e5%ae%9e%e7%8e%b0%e4%b8%8e%e8%a7%a3%e9%87%8a%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=5319","title":{"rendered":"Java\u7248\u534f\u540c\u8fc7\u6ee4\u7b97\u6cd5\u7ec8\u6781\u5b9e\u73b0\u4e0e\u89e3\u91ca\uff01"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e4b\u524d\u6709\u4e00\u4e2a\u667a\u80fd\u97f3\u4e50\u63a8\u8350\u7cfb\u7edf\uff0c\u7528\u5230\u4e86\u534f\u540c\u8fc7\u6ee4\u7b97\u6cd5\uff01\u4eca\u5929\u901a\u8fc7 demo \u4ee3\u7801\uff0c\u5927\u81f4\u7684\u7ed9\u5927\u5bb6\u89e3\u91ca\u4e00\u4e0b\u539f\u7406\u548cJava\u5b9e\u73b0\u3002\u4e0b\u9762\u76f4\u63a5\u8d34\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\/**\n * \u6b64\u65b9\u6cd5\u4f7f\u7528\u534f\u540c\u8fc7\u6ee4\u7b97\u6cd5\uff0c\u5927\u6982\u610f\u601d\u5c31\u662f\u4ece\u6570\u636e\u5e93\u62ff\u5230\u6240\u6709\u7684\u7528\u6237\u6536\u85cf\u548c\u5f53\u524d\u7684\u7528\u6237\u6536\u85cf\u4f5c\u4e3a\u6bd4\u5bf9\uff0c\u627e\u51fa\u548c\u5f53\u524d\u7528\u6237\u6536\u85cf\u5939\u6700\u63a5\u8fd1\u7684\u4e00\u4e2a\u7528\u6237\uff0c\n * \u7136\u540e\u5c06\u90a3\u4e2a\u7528\u6237\u7684\u6536\u85cf\u4e2d\u5f53\u524d\u767b\u5f55\u7528\u6237\u6ca1\u6709\u7684\u5c55\u793a\u7ed9\u5f53\u524d\u7528\u6237\n * @param model\n * @param request\n * @return\n *\/\n\/*\n\u4e3e\u4f8b\u8bf4\u660e\u4e00\u4e0b\uff0c\u6bd4\u5982\u5f53\u524d\u767b\u5f55userid = 1\n\u7528\u6237\u5173\u8054\u8868\u4e2d\u6570\u636e\uff0c\n\u7528\u62371\u5173\u8054\u6b4c\u66f2\uff5b2\uff0c3\uff5d\uff08\u5f53\u524d\u767b\u5f55\u7528\u6237\u6536\u85cf\u7684\u6b4c\u66f2\uff09\n\u7528\u62372\u5173\u8054\u6b4c\u66f2\uff5b2\uff0c3\uff0c4\uff5d\n\u7528\u62373\u5173\u8054\u6b4c\u66f2\uff5b3\uff0c4\uff0c5\uff5d\n\u7528\u62374\u5173\u8054\u6b4c\u66f2\uff5b1\uff0c5\uff5d\n*\/\n@RequestMapping(value = \"\/getRecommendList\", method = RequestMethod.GET)\npublic String getRecommendList(Model model, HttpServletRequest request) {\/\/ \u534f\u540c\u8fc7\u6ee4\u7b97\u6cd5\n\tHttpSession httpSession = request.getSession();\n\tString name = httpSession.getAttribute(\"name\").toString();\n\n\t\/\/ \u83b7\u53d6userId\n\tint orginal = userService.getUserByName(name).getId(); \/\/\u5bf9\u5e94\u6a21\u62df\u6570\u636e\uff0c\u8fd9\u4e2a\u503c\u4e3a1\n\n\t\/\/ \u83b7\u53d6\u6240\u6709\u7528\u6237\u548c\u6b4c\u66f2\u7684\u5173\u8054\n\tList&lt;Enshrine&gt; all = enshrineService.getAll();\/\/\u521a\u624d\u6240\u6709\u7684\u6a21\u62df\u6570\u636e \u7b2c\u4e00\u4e2aenshrine\u5bf9\u8c61\u503c\u4e3auserid=1,movieid=2,\u7b2c\u4e8c\u4e2auserid=1,movieid=2 \u3002\u3002\u3002 \u8fd9\u4e2a\u96c6\u5408\u7684\u957f\u5ea6=\u6240\u6709\u7528\u6237\u6536\u85cf\u7684\u6b4c\u66f2\u7684\u957f\u5ea6\uff0c\u6240\u4ee5\u8bf4all\u96c6\u5408\u7684\u957f\u5ea6\u4e3a10\n\n\t\/\/ \u521b\u5efa\u7528\u6237\u63a8\u8350map\uff0c\u6570\u636e\u7ed3\u6784\u4e3a key:Integer \u5bf9\u5e94\u7528\u6237id value:List \u5bf9\u5e94\u4e00\u4e2a\u5e7f\u544a\u7684id\u96c6\u5408\n\tHashMap&lt;Integer, List&lt;Integer&gt;&gt; userRecommend = new HashMap();\n\n\t\/\/ \u904d\u5386\u6240\u6709\u7684\u5173\u8054\n\t\/*\n\t\u7b2c1\u6b21\u5faa\u73af userid=1,movieid=2\n\t\u7b2c2\u6b21\u5faa\u73af userid=1,movieid=3\n\t\u7b2c3\u6b21\u5faa\u73af userid=2,movieid=2\n\t\u7b2c4\u6b21\u5faa\u73af userid=2,movieid=3\n\t\u7b2c5\u6b21\u5faa\u73af userid=2,movieid=4\n\t\u7b2c6\u6b21\u5faa\u73af userid=3,movieid=3\n\t\u7b2c7\u6b21\u5faa\u73af userid=3,movieid=4\n\t\u7b2c8\u6b21\u5faa\u73af userid=3,movieid=5\n\t\u7b2c9\u6b21\u5faa\u73af userid=4,movieid=1\n\t\u7b2c10\u6b21\u5faa\u73af userid=4,movieid=5\n\t\u8fd9\u4e2a\u518d\u770b\u4e0d\u61c2\u7684\u8bdd\uff0co(\u2229_\u2229)o \n\t**\/\n\n\tfor (int i = 0; i &lt; all.size(); i++) {\n\t\t\/\/ \u83b7\u53d6\u6bcf\u4e00\u4e2a\u7528\u6237\u548c\u6b4c\u66f2Id\n\t\tint userId = all.get(i).getUser_id(); \/\/\u7b2c\u4e00\u6b21\u5faa\u73af userId=1\n\t\tint movieid = all.get(i).getMovie_id(); \/\/ \u7b2c\u4e00\u6b21\u5faa\u73af movie_id=2\n\t\t\/\/ \u5982\u679c\u63a8\u8350map\u4e2d\u6709\u4ee5\u5f53\u524d\u7528\u6237\u4e3aKey\u7684\u6570\u636e\n\t\tif (userRecommend.containsKey(userId)) { \/\/\u7b2c\u4e00\u6b21\u5faa\u73af\uff0c\u8fd9\u4e2amap\u662f\u65b0\u5efa\u7684\uff0c\u80af\u5b9a\u90fd\u662fNull\uff0c\u6240\u4ee5userRecommend\u80af\u5b9a\u6ca1\u6709\u4ee5\u5f53\u524d\u7528\u6237id\u4f5c\u4e3akey\u7684\u503c\n\t\t\t\/\/ \u6839\u636e\u7528\u6237id\u83b7\u53d6map\u5bf9\u5e94\u7684value\n\t\t\tList&lt;Integer&gt; recommendTemp = userRecommend.get(userId);\n\t\t\t\/\/ \u5728\u62ff\u5230\u7684\u96c6\u5408\u4e2d\u6dfb\u52a0\u65b0\u7684\u6b4c\u66f2id\n\t\t\trecommendTemp.add(movie_id);\n\t\t\t\/\/ \u66f4\u65b0\u6b64key value\n\t\t\tuserRecommend.put(userId, recommendTemp);\n\t\t} else {\n\t\t\t\/\/ \u5982\u679c\u4e0d\u5305\u542b\uff0c\u65b0\u5efa\u4e00\u4e2a\u96c6\u5408\uff0c\u7136\u540e\u5c06Key value\u653e\u5165map\n\t\t\tList&lt;Integer&gt; recommendTemp = new ArrayList&lt;&gt;();  \/\/\u6ca1\u6709\u503c\u5c31\u65b0\u5efa\u4e00\u4e2aList\n\t\t\trecommendTemp.add(movie_id);\t\t\t\t\t  \/\/ \u6dfb\u52a0\u5f53\u524d\u5faa\u73af\u7684\u8fd9\u4e2amovieid,\u8fd9\u4e2a\u96c6\u5408\u7684\u6570\u636e\u5c31\u662f [2]\n\t\t\tuserRecommend.put(userId, recommendTemp);         \/\/ \u5c06\u5f53\u524d\u5faa\u73af\u7684userid\u4f5c\u4e3akey\uff0c\u96c6\u5408\u4f5c\u4e3avalue\u653e\u5165userRecommend\u4e2d\uff0c\u6b64\u65f6map\u4e2d\u7684\u503c\u4e3a\uff5b1\uff0c[2]\uff5d\n\t\t}\n\t}\n\t\/*\n\t*\u6bcf\u6b21\u5faa\u73afuserRecommend\u7684\u503c\u7684\u53d8\u5316\n\t{{1\uff0c[2]}}\n\t{{1\uff0c[2\uff0c3]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3,4]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3,4]},{3,[3]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3,4]},{3,[3,4]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3,4]},{3,[3,4,5]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3,4]},{3,[3,4,5]}\uff0c{4,[1]}}\n\t{{1\uff0c[2\uff0c3]},{2\uff0c[2,3,4]},{3,[3,4,5]}\uff0c{4,[1\uff0c5]}} \u6700\u7ec8\u5f62\u6001\n\t*\/\n\n\t\/\/\u6ce8\u610f\u5982\u679c\u5f53\u524d\u767b\u5f55\u7528\u6237\u6ca1\u6709\u6536\u85cf\u8fc7\u4efb\u4f55\u6b4c\u66f2\uff0c\u8fd9\u4e2amap\u4e2d\u5c31\u4e0d\u4f1a\u6709\u4ee5\u5f53\u524d\u767b\u5f55\u7528\u6237\u4e3akey\u7684value\u4e86\n\n\n\t\/\/ \u65b0\u5efa\u6211\u7684\u6b4c\u5355\n\tList&lt;Integer&gt; myRecommend = new ArrayList&lt;&gt;();\n\t\/\/ \u5982\u679c\u521a\u624d\u5b58\u653e\u7684map\u4e2d\u5305\u542b\u6709\u4ee5\u5f53\u524d\u767b\u5f55\u7528\u6237id\u4e3akey\u7684\u6570\u636e\n\tif (userRecommend.containsKey(orginal)) { \n\t\t\/\/ \u5219\u6211\u7684\u6b4c\u5355 = \u4ece\u6b4c\u5355\u5217\u8868\u4e2d\u83b7\u53d6\u7684\u96c6\u5408\n\t\tmyRecommend = userRecommend.get(orginal);\n\t\t\/\/ System.out.println(\"orginal: \" + orginal);\n\t\t\/\/ System.out.println(\"mySize: \" + myRecommend.size());\n\t} else {\n\t\tmyRecommend = new ArrayList&lt;&gt;();\n\t}\n\n\t\/*\n\t\t\u4ecemap\u4e2d\u53d6\u51fa\u521a\u624d\u5b58\u5165\u7684\u5f53\u524d\u7528\u6237\u7684\u6b4c\u5355\n\t\tmyRecommend = [2\uff0c3]\n\t\t\u5982\u679c\u7528\u6237\u6ca1\u6709\u6536\u85cf\u4efb\u4f55\u7684\u6b4c\u66f2\n\t\tmyRecommend = []\n\t\t\u5f53\u524d\u7684\u6a21\u62df\u6570\u636e\u662f\u6709\u6b4c\u66f2\u7684\uff0c\u6240\u4ee5\u662f\u7b2c\u4e00\u4e2a\n\t*\/\n\n\n\n\t\/\/ \u5c06\u6211\u7684\u6b4c\u5355\u5217\u8868\u96c6\u5408\u8f6c\u6362\u4e3aset\u96c6\u5408\n\tHashSet&lt;Integer&gt; myRecommendSet = new HashSet&lt;Integer&gt;(myRecommend);\n\tdouble maxValue = 0;\n\tint maxId = -1;\n\t\/\/ \u904d\u5386\u63a8\u8350\u5217\u8868\u4e2d\u6240\u6709\u70b9key\n\t\/*\n\t\u8fd9\u4e2akeySet()\u65b9\u6cd5\uff0c\u76f8\u5f53\u4e8e\u5c06userRecommend\u6240\u6709Key\u62ff\u51fa\u6765\u653e\u5165\u4e00\u4e2a\u96c6\u5408\u4e2d\n\t\u6570\u636e\u7ed3\u6784\u5c31\u662f[1,2,3,4]\n\t*\/\n\n\t\/*\n\t\t\u5faa\u73af[1,2,3,4]\n\n\t\t\u7b2c\u4e00\u6b21\u5faa\u73af key=1\n\t\t\u5faa\u73af\u7684\u662f\u5f53\u524d\u7528\u6237\u7684id\uff0c\u6240\u4ee5\u8df3\u8fc7\u8fd9\u6b21\u5faa\u73af\n\n\t\t\u7b2c\u4e8c\u6b21 key=2\n\t\t\u4eceuserRecommend\u62ff\u5230\u6240\u6709\u7684\u6b4c\u66f2\u96c6\u5408\n\t\t\u62ff\u5230\u4e86[2,3,4]\n\t\t\u548c\u6211\u7684\u6b4c\u66f2\u96c6\u5408myRecommend=[2\uff0c3]\u505a\u5bf9\u6bd4\n\t\t\u53d6\u4ea4\u96c6\u83b7\u53d6\u65b0\u96c6\u5408 intersection = [2,3]\n\t\t\u521b\u5efa\u4e00\u4e2a\u65b0\u96c6\u5408union\u653e\u5165\u6211\u7684\u6b4c\u66f2\u96c6\u5408union = [2,3]\n\t\t\u628a\u5f53\u524d\u5faa\u73af\u7528\u6237\u7684\u6b4c\u66f2\u96c6\u5408\u653e\u5165union\uff0c\u56e0\u4e3a\u662fset\u96c6\u5408\u4f1a\u53bb\u6389\u91cd\u590d\u7684\u5143\u7d20\u6240\u4ee5 union=[2,3,4]\n\t\t\u7528intersection\u6b64\u65f6\u7684\u957f\u5ea62\/union\u6b64\u65f6\u7684\u957f\u5ea63 \u5f97\u5230\u4e00\u4e2aratio\u5c0f\u6570 \u53ef\u4ee5\u5c06\u5b83\u770b\u4f5c\u4e3a67% ratio=0.67\n\t\t\u6b64\u65f6maxValue\u7684\u503c\u4e3a0\uff0c0.67 &gt; 0\n\t\t\u6240\u4ee5\u8bbe\u7f6emaxValue\u7684\u503c\u4e3a0.67\n\t\tmaxId = \u5f53\u524d\u5faa\u73af\u7684\u7528\u6237id = 2\n\n\t\t\u7b2c\u4e09\u6b21 key=3\n\t\t\u4eceuserRecommend\u62ff\u5230\u6240\u6709\u7684\u6b4c\u66f2\u96c6\u5408\n\t\t\u62ff\u5230\u4e86[3,4,5]\n\t\t\u548c\u6211\u7684\u6b4c\u66f2\u96c6\u5408myRecommend=[2\uff0c3]\u505a\u5bf9\u6bd4\n\t\t\u53d6\u4ea4\u96c6\u83b7\u53d6\u65b0\u96c6\u5408 intersection = [3]\n\t\t\u521b\u5efa\u4e00\u4e2a\u65b0\u96c6\u5408union\u653e\u5165\u6211\u7684\u6b4c\u66f2\u96c6\u5408union = [2,3]\n\t\t\u628a\u5f53\u524d\u5faa\u73af\u7528\u6237\u7684\u6b4c\u66f2\u96c6\u5408\u653e\u5165union\uff0c\u56e0\u4e3a\u662fset\u96c6\u5408\u4f1a\u53bb\u6389\u91cd\u590d\u7684\u5143\u7d20\u6240\u4ee5 union=[2,3,4,5]\n\t\t\u7528intersection\u6b64\u65f6\u7684\u957f\u5ea61\/union\u6b64\u65f6\u7684\u957f\u5ea64 \u5f97\u5230\u4e00\u4e2aratio\u5c0f\u6570  ratio=0.25\n\t\t\u6b64\u65f6maxValue\u7684\u503c\u4e3a0.67\uff0c0.25 &lt; 0.67\n\t\t\u6240\u4ee5maxValue\u7684\u503c\u4e0d\u53d8 = 0.67\n\t\tmaxId\u4e0d\u53d8 = 2\n\n\t\t\u7b2c\u56db\u6b21 key=4\n\t\t\u4eceuserRecommend\u62ff\u5230\u6240\u6709\u7684\u6b4c\u66f2\u96c6\u5408\n\t\t\u62ff\u5230\u4e86[1\uff0c5]\n\t\t\u548c\u6211\u7684\u6b4c\u66f2\u96c6\u5408myRecommend=[2\uff0c3]\u505a\u5bf9\u6bd4\n\t\t\u53d6\u4ea4\u96c6\u83b7\u53d6\u65b0\u96c6\u5408 intersection = []\n\t\t\u521b\u5efa\u4e00\u4e2a\u65b0\u96c6\u5408union\u653e\u5165\u6211\u7684\u6b4c\u66f2\u96c6\u5408union = [2,3]\n\t\t\u628a\u5f53\u524d\u5faa\u73af\u7528\u6237\u7684\u6b4c\u66f2\u96c6\u5408\u653e\u5165union\uff0c\u56e0\u4e3a\u662fset\u96c6\u5408\u4f1a\u53bb\u6389\u91cd\u590d\u7684\u5143\u7d20\u6240\u4ee5 union=[2,3]\n\t\t\u7528intersection\u6b64\u65f6\u7684\u957f\u5ea60\/union\u6b64\u65f6\u7684\u957f\u5ea62 \u5f97\u5230\u4e00\u4e2aratio\u5c0f\u6570 ratio=0\n\t\t\u6b64\u65f6maxValue\u7684\u503c\u4e3a0.67\uff0c0 &lt; 0.67\n\t\t\u6240\u4ee5maxValue\u7684\u503c\u4e0d\u53d8 = 0.67\n\t\tmaxId\u4e0d\u53d8 = 2\n\t*\/\n\tfor (int key : userRecommend.keySet()) {\n\t\t\/\/ \u5f53\u904d\u5386\u5230\u5f53\u524d\u7528\u6237Id\u4e3akey\u7684\u65f6\u5019\uff0c\u8df3\u8fc7\u6b64\u6b21\u5faa\u73af\uff0c\u5f00\u59cb\u4e0b\u4e00\u6b21\u5faa\u73af\n\t\tif (key == orginal) {\n\t\t\tcontinue;\n\t\t}\n\t\t\/\/ \u6839\u636e\u5f53\u524d\u5faa\u73af\u5230\u7684key\u83b7\u53d6value\uff0c\u4e5f\u5c31\u662f\u5bf9\u5e94\u6b64\u7528\u6237\u6b4c\u66f2\u7684\u96c6\u5408\n\t\tList&lt;Integer&gt; thisRecommend = userRecommend.get(key);\n\t\t\/\/ System.out.println(\"thisSize: \" + thisRecommend.size());\n\t\t\/\/ \u5c06\u5f53\u524d\u6b4c\u66f2\u7684\u96c6\u5408\u8f6c\u6362\u4e3aset\n\t\tHashSet&lt;Integer&gt; thisRecommendSet = new HashSet&lt;&gt;(thisRecommend);\n\t\t\/\/ \u5c06\u6211\u7684\u6b4c\u66f2\u96c6\u5408\u8f6c\u6362\u4e3aset\n\t\tHashSet&lt;Integer&gt; intersection = new HashSet&lt;&gt;(myRecommendSet);\n\t\t\/\/ \u53d6\u4ea4\u96c6 \u6211\u7684\u6b4c\u66f2\u4f1a\u5269\u4e0b\u4e24\u4e2a\u96c6\u5408\u4e2d\u90fd\u6709\u7684\u6b4c\u66f2id\n\t\tintersection.retainAll(thisRecommendSet);\n\t\tHashSet&lt;Integer&gt; union = new HashSet&lt;&gt;(myRecommendSet);\n\t\t\/\/ System.out.println(\"union1: \" + union.size());\n\t\t\/\/ \u5c06\u4e24\u4e2a\u4eba\u6536\u85cf\u7684\u6240\u6709\u6b4c\u66f2\u53bb\u91cd\u5e76\u653e\u5165\u6b64\u96c6\u5408\u4e2d\n\t\tunion.addAll(thisRecommendSet);\n\t\t\/\/ System.out.println(\"union2: \" + union.size());\n\t\t\/\/ \u5982\u679c\u53d6\u8fc7\u4ea4\u96c6\u7684\u96c6\u5408\u4e3a\u7a7a\uff0c\u8bf4\u660e\u5f53\u524d\u5faa\u73af\u5230\u7684\u7528\u6237\u548c\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u6ca1\u6709\u6536\u85cf\u540c\u4e00\u79cd\u6b4c\u66f2\uff0c\u8df3\u8fc7\u6b64\u6b21\u5faa\u73af\uff0c\u5f00\u59cb\u4e0b\u4e00\u6b21\u5faa\u73af\n\t\tif (union.size() == 0) {\n\t\t\tcontinue;\n\t\t} else {\n\t\t\t\/\/ \u5982\u679c\u4e0d\u4e3a\u7a7a\uff0c\u5219\u7528\u6211\u7684\u6b4c\u66f2\u5217\u8868\/\u4ea4\u96c6\u96c6\u5408\n\t\t\tdouble ratio = (double) intersection.size() \/ union.size();\n\t\t\tif (ratio &gt; maxValue) {\n\t\t\t\t\/\/ \u6700\u5927\u503c\u5c31\u4f4d\u4e24\u8005\u4e4b\u6bd4\n\t\t\t\tmaxValue = ratio;\n\t\t\t\t\/\/ maxId = \u5f53\u524d\u5faa\u73af\u7684\u7528\u6237\n\t\t\t\tmaxId = key;\n\t\t\t}\n\t\t}\n\t}\n\n\n\t\/\/ \u521b\u5efa\u6b4c\u66f2\u63a8\u8350\u5217\u8868\n\tList&lt;Integer&gt; MovieRecommendList = new ArrayList&lt;&gt;();\n\t\/\/\u3000\u5982\u679c\uff4d\uff41\uff58\uff29\uff24\u6ca1\u6709\u88ab\u66f4\u6539\u8fc7\uff0c\u5219\u4e3a\u5f53\u524d\u767b\u5f55\u7528\u6237ID\n\tif (maxId == -1) { \/\/\u6b64\u65f6maxId = 2\n\t\tmaxId = orginal;\n\t} else {\n\t\t\/\/ \u5982\u679c\u88ab\u66f4\u6539\u8fc7\uff0c\u5c31\u4ece\u63a8\u8350\u5217\u8868\u4e2d\u53d6\u51fakey\u4e3amaxId\uff08maxId\u4e3a\u62e5\u6709\u6700\u5927\u4ea4\u96c6\u7684\u7528\u6237id\uff09 \u7684\u6b4c\u66f2\u5217\u8868\uff0c\n\t\tHashSet&lt;Integer&gt; differenceTemp = new HashSet&lt;&gt;(userRecommend.get(maxId)); \/\/ differenceTemp = [2,3,4]\n\t\t\/\/ maxId\u7528\u6237\u6b4c\u5355\u5217\u8868\u4e2d\u7684\u6b4c\u66f2 - \u6211\u7684\u6b4c\u5355\u5217\u8868\u4e2d\u7684\u6b4c\u66f2 = \u6211\u6ca1\u6709\u7684\u6b4c\u66f2\n\t\tdifferenceTemp.removeAll(myRecommendSet); \/\/ differenceTemp = [4] \u6240\u4ee5\uff0c\u5728\u63a8\u8350\u5217\u8868\u4e2d\u5c31\u4f1a\u51fa\u73b0id\u4e3a4\u7684\u6b4c\u66f2\uff0c\u5269\u4e0b\u7684\u5c31\u662f\u8ba1\u7b97\u76f8\u4f3c\u5ea6\u548c\u5c06\u6b4c\u66f2\u4f20\u5230\u524d\u53f0\u4e86\uff01\n\t\tMovieRecommendList = new ArrayList&lt;Integer&gt;(differenceTemp); \n\t}\n\t\/\/ \u4e00\u4e0b\u4ee3\u7801\u5c31\u662f\u4ece\u6211\u6ca1\u6709\u7684\u6b4c\u66f2\u5217\u8868id\u4e2d\u53d6\u5f97\u6b4c\u66f2\u4fe1\u606f\n\tList&lt;Advertisement&gt; movies = new ArrayList&lt;&gt;();\n\tfor (int i = 0; i &lt; MovieRecommendList.size(); i++) {\n\t\tAdvertisement movie = advertisementService.getMovieById(MovieRecommendList.get(i));\n\t\tmovies.add(movie);\n\t}\n\tmodel.addAttribute(\"professor\", movies);\n\/\/\t\tSystem.out.println(movies.size());\n\tDecimalFormat df=new DecimalFormat(\"0.00\");\n\t\/\/ \u6b4c\u5355\u76f8\u4f3c\u5ea6 = \u6211\u7684\u6b4c\u5355\u957f\u5ea6\/(\u6211\u7684\u6b4c\u5355\u957f\u5ea6 + \u6211\u6ca1\u6709\u7684\u6b4c\u66f2\u957f\u5ea6) * 100%\n\tString similar = \"\u6b4c\u5355\u76f8\u4f3c\u5ea6\uff1a\"+df.format((float)myRecommendSet.size()\/(myRecommendSet.size()+movies.size())*100)+\"%\";\n\tSystem.out.println(similar);\n\t model.addAttribute(\"similar\", similar);\n\treturn \"recommend\";\n}<\/code><\/pre>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=5319\">Java\u7248\u534f\u540c\u8fc7\u6ee4\u7b97\u6cd5\u7ec8\u6781\u5b9e\u73b0\u4e0e\u89e3\u91ca\uff01<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u6709\u4e00\u4e2a\u667a\u80fd\u97f3\u4e50\u63a8\u8350\u7cfb\u7edf\uff0c\u7528\u5230\u4e86\u534f\u540c\u8fc7\u6ee4\u7b97\u6cd5\uff01\u4eca\u5929\u901a\u8fc7 demo \u4ee3\u7801\uff0c\u5927\u81f4\u7684\u7ed9\u5927\u5bb6\u89e3\u91ca\u4e00\u4e0b\u539f\u7406\u548cJava\u5b9e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[871,685,872,172,75],"class_list":["post-5319","post","type-post","status-publish","format-standard","hentry","category-yyzt","tag-idea","tag-685","tag-872","tag-172","tag-75"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5319","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5319"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5319\/revisions"}],"predecessor-version":[{"id":5320,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/5319\/revisions\/5320"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}