From 4f60452bd824ae6d8efc888f95731b2541b0d4f1 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Mon, 19 Jun 2023 17:53:31 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BF=AE=E5=A4=8D=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E9=A1=B5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Chenx221 --- .../controller/PersonController.class | Bin 5007 -> 4958 bytes .../WEB-INF/views/person.jsp | 73 ++++++++++------- project2/project2.sql | 28 ++++--- .../chenx221/controller/PersonController.java | 3 +- project2/web/WEB-INF/views/person.jsp | 74 +++++++++++------- 5 files changed, 104 insertions(+), 74 deletions(-) diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/PersonController.class b/project2/out/artifacts/project2_war_exploded/WEB-INF/classes/cyou/chenx221/controller/PersonController.class index c595d2c13140aa6e21d49ba1bcec8041c99e4cd0..1d28fc444fbca90c71357cd29627e92c8fdb3286 100644 GIT binary patch delta 1207 zcmY+D`%{!<6vsc$-d=Zk+g&yxAOwmKN3a=(nVKALsN4mkFf+|UU5UgD7AdVjtn8{- zPxrgs@1YQ~P#Wd*L(`woH2nwt15NgQ-`%15;ob9`@AI7RIp=%MPSpOsJod}qa~FYi z{B$mMGMJ3f$R>x)E?a0a)Y`M*Qu{|ZZd*bvro~Q#N-CRab7|*lL#!`7+?mc~di&BT zacp(zq|5#sYAU(a;2g@`6mT22JM_40=MH-**qw}WCp#VPa@oahL$z{L+qUqgqDJ<( z+{3+wNM^Wq_(;aEdxb4@i)>{iY&V2s_Hy`^_+Iuo>~~3f1vcahEVJt)(TYApvg>fw zf&PJX)lhn0x_>0S-|MK~<$ey@bflyFkjn#f8KSDaain*+cPPdR9&{OG$o?AHo@!*+ zYyO}YH{$XT58DQ(J${Tw93FLfj8Vf)`K$>$;KZjEoM~fDPmM$uLha zHpMTSIU7r~hb|dv>|nem=&)dqCz`GqlVTAJ$7MsZVa5q?!v2=Hw&`(Uaf13?rn?HF zRPuzpV!ePEPjXV$I~Cw6_P<<)r+C_DTAN%o<}szj0o8hY0|{y=sOwN72S*`|%}_T^bA z0hVcvK2^qm(5Nqkw`8mHQY_W|=Mu{J%aFoc5kbK3_LSG^U~|6JFaFo+zdQ1!QhX)C u0ADY@_(r~0XikiCoR_aXV@h9^d3j|jey{$4-$kMvll@-yB0umWrT+l!h}{GL delta 1193 zcmY+D`%{!<6vsc$UU+wxw_RAtfDkBB7{Q^&nPzN8lN2>>f`XScb<+ixKy;U|n{Has zjYNC9-^;FcLowXNvMkG)X8N@s`?)`&vhVw{L-oVE=XuU~&i9<}_niHG$z*-xm%nE( z0V}zBHZtyS4$)!=C&m(^iF99jD8w4WbCDK1=G1UvAX!W+>nzsWY~XI^bfBjs zLOUH6oi<%;G}JrCOqugnaDj8xzuxpXu|RoEH=AvGSzw3^Bu6`wnT(L)s=LKzE8CoP zf!6YS4A$^mB+O3kwb*5|n>~&R?hmzdpUqzOIfsIS(S8Oj_S>Y~a?1!lO>9)fPQU*5WanV;nc!?pB;WV*O^!3)8*f%YkSvLY`TRi!PgQoVw^0bIJK5 z+7|fHu-Hk&s-5Ae<+u3B*%fQO;c@XU!tjJ_KsLye_!xI)V>h-wC0`W3eitcLO_&;< z)@`9)K!j&_R@OZgV=MQ+Scd1A@Q^A?mStU}xGGbuF7=(=2^(N1!Rby&^CdJI9V3iKaYBA5-$j2j~1b zh6+vwcdZu}^nJ^Bx>c(Ae*NjbFA8&1_Ok2`T*3b{75@O-Slylg diff --git a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/person.jsp b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/person.jsp index 28fb270..4d3842a 100644 --- a/project2/out/artifacts/project2_war_exploded/WEB-INF/views/person.jsp +++ b/project2/out/artifacts/project2_war_exploded/WEB-INF/views/person.jsp @@ -140,32 +140,33 @@
-
-
-
-

- Avatar: -

-
-
- - -
-
- - -
+ +
+
+

+ 头像设置: +

-
-
- -
+
+ +
- +
+ + +
+
+
+
+ <%-- Todo: 换成消息框--%> +
+
@@ -212,7 +213,21 @@ $('#exampleModal').modal('show'); - $('#customFile').on('change', function() { + fetch("/person/image") + .then(function (response) { + if (response.ok) { + // 图像存在,显示自定义头像 + $('#custom_avatar').show(); + } else { + // 图像不存在,显示默认头像 + $('#default_avatar').show(); + } + }) + .catch(function (error) { + console.log("请求失败:", error); + }); + + $('#customFile').on('change', function () { var file = this.files[0]; // 获取选择的文件 // 检查是否选择了文件 @@ -232,12 +247,12 @@ data: formData, processData: false, // 告诉jQuery不要处理FormData对象 contentType: false, // 告诉jQuery不要设置Content-Type请求头 - success: function(response) { - // 成功上传后的操作 + success: function () { $('#default_avatar').hide(); // 隐藏默认头像 - $('#custom_avatar').attr('src', response.avatarUrl).show(); // 更新自定义头像的图像源 + $('#custom_avatar').show(); // 显示自定义头像 + $('#note').show(); // 显示提示消息 }, - error: function(xhr, status, error) { + error: function (xhr, status, error) { console.log('上传失败:', error); alert('上传失败,请重试'); } diff --git a/project2/project2.sql b/project2/project2.sql index a13b071..c178867 100644 --- a/project2/project2.sql +++ b/project2/project2.sql @@ -11,7 +11,7 @@ Target Server Version : 80033 (8.0.33) File Encoding : 65001 - Date: 19/06/2023 10:39:55 + Date: 19/06/2023 16:23:38 */ SET NAMES utf8mb4; @@ -80,7 +80,7 @@ CREATE TABLE `score` ( INDEX `fk_course`(`CourseID` ASC) USING BTREE, CONSTRAINT `fk_course` FOREIGN KEY (`CourseID`) REFERENCES `course` (`CourseID`) ON DELETE RESTRICT ON UPDATE RESTRICT, CONSTRAINT `fk_student` FOREIGN KEY (`StudentID`) REFERENCES `student` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT -) ENGINE = InnoDB AUTO_INCREMENT = 122 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; +) ENGINE = InnoDB AUTO_INCREMENT = 123 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of score @@ -206,6 +206,7 @@ INSERT INTO `score` VALUES (118, 667, 9, 47, 0); INSERT INTO `score` VALUES (119, 586, 5, 9, 0); INSERT INTO `score` VALUES (120, 849, 11, 32, 0); INSERT INTO `score` VALUES (121, 1, 1, 100, 0); +INSERT INTO `score` VALUES (122, 1, 2, 0, 0); -- ---------------------------- -- Table structure for student @@ -1285,25 +1286,26 @@ INSERT INTO `teacher` VALUES (22, '无名氏4', '男', '2023-06-17', 1, '2班', DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` int NOT NULL AUTO_INCREMENT COMMENT '用户ID', - `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '用户名', + `username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '用户名', `password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '密码', `roles` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT 'admin' COMMENT '角色(admin,student,teacher)', `disabled` int NULL DEFAULT 0 COMMENT '禁用(default: 0 false)', `detail` int NULL DEFAULT NULL COMMENT 'link to roles id', - PRIMARY KEY (`id`) USING BTREE + `photo` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'link to avatar filename', + PRIMARY KEY (`id`, `username`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of user -- ---------------------------- -INSERT INTO `user` VALUES (1, 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', 'admin', 0, NULL); -INSERT INTO `user` VALUES (2, 'guest', '84983c60f7daadc1cb8698621f802c0d9f9a3c3c295c810748fb048115c186ec', 'admin', 1, NULL); -INSERT INTO `user` VALUES (3, 'chenx221', '62982ab94542113a449fc9528779583bb6b93988ac4678c3fd6c010b66e7a851', 'admin', 1, NULL); -INSERT INTO `user` VALUES (4, 'chenx2210', '2bd27a9cb9135ff37aee523b7e439873a46da4d5b482145927b991a95baf43bb', 'admin', 0, NULL); -INSERT INTO `user` VALUES (5, 'newuser1', '7dcf407fa84a0e0519c7991154c4148de0244d7589020c0d9842db9efad82094', 'admin', 0, NULL); -INSERT INTO `user` VALUES (6, 'guest2', '6b93ccba414ac1d0ae1e77f3fac560c748a6701ed6946735a49d463351518e16', 'admin', 0, NULL); -INSERT INTO `user` VALUES (7, 'student1', '49fe07d0f041bced9ba827a10c2cd31b2089229d4b4e3a63b074ed7a4370e88f', 'student', 0, 0); -INSERT INTO `user` VALUES (8, 'student2', '2d850eb5460ffb6bb9ae11186a2d78cc22d9df387f9cdbd3a297e0d1ea08a54b', 'student', 0, 4); -INSERT INTO `user` VALUES (9, 'teacher1', '0829db2785c8de0ad7d0231c903be3083f6729679bc69b092bf4cfd3dc629006', 'teacher', 0, 1); +INSERT INTO `user` VALUES (1, 'admin', '8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918', 'admin', 0, NULL, 'efe7ea02-053b-4b77-b8b1-719d13b18d18_010 (2)_512.png'); +INSERT INTO `user` VALUES (2, 'guest', '84983c60f7daadc1cb8698621f802c0d9f9a3c3c295c810748fb048115c186ec', 'admin', 1, NULL, NULL); +INSERT INTO `user` VALUES (3, 'chenx221', '62982ab94542113a449fc9528779583bb6b93988ac4678c3fd6c010b66e7a851', 'admin', 1, NULL, NULL); +INSERT INTO `user` VALUES (4, 'chenx2210', '2bd27a9cb9135ff37aee523b7e439873a46da4d5b482145927b991a95baf43bb', 'admin', 0, NULL, NULL); +INSERT INTO `user` VALUES (5, 'newuser1', '7dcf407fa84a0e0519c7991154c4148de0244d7589020c0d9842db9efad82094', 'admin', 0, NULL, NULL); +INSERT INTO `user` VALUES (6, 'guest2', '6b93ccba414ac1d0ae1e77f3fac560c748a6701ed6946735a49d463351518e16', 'admin', 0, NULL, NULL); +INSERT INTO `user` VALUES (7, 'student1', '49fe07d0f041bced9ba827a10c2cd31b2089229d4b4e3a63b074ed7a4370e88f', 'student', 0, 0, NULL); +INSERT INTO `user` VALUES (8, 'student2', '2d850eb5460ffb6bb9ae11186a2d78cc22d9df387f9cdbd3a297e0d1ea08a54b', 'student', 0, 4, NULL); +INSERT INTO `user` VALUES (9, 'teacher1', '0829db2785c8de0ad7d0231c903be3083f6729679bc69b092bf4cfd3dc629006', 'teacher', 0, 1, NULL); SET FOREIGN_KEY_CHECKS = 1; diff --git a/project2/src/main/java/cyou/chenx221/controller/PersonController.java b/project2/src/main/java/cyou/chenx221/controller/PersonController.java index 04eb7b5..13331e9 100644 --- a/project2/src/main/java/cyou/chenx221/controller/PersonController.java +++ b/project2/src/main/java/cyou/chenx221/controller/PersonController.java @@ -54,9 +54,8 @@ public class PersonController { user.setAvatar(object); userMapper.setAvatar(user); // 设置返回的avatarUrl值 - response.put("avatarUrl", "/person/image"); +// response.put("avatarUrl", "/person/image"); // response.put("avatarUrl", avatarUrl); - // 返回成功消息和avatarUrl return ResponseEntity.ok(response); } catch (Exception e) { diff --git a/project2/web/WEB-INF/views/person.jsp b/project2/web/WEB-INF/views/person.jsp index 850c31c..4d3842a 100644 --- a/project2/web/WEB-INF/views/person.jsp +++ b/project2/web/WEB-INF/views/person.jsp @@ -140,33 +140,33 @@
-
-
-
-

- Avatar: -

-
-
- - -
-
- - -
+ +
+
+

+ 头像设置: +

-
-
-<%-- --%> -<%-- Todo: 换成消息框--%> -
+
+ +
- +
+ + +
+
+
+
+ <%-- Todo: 换成消息框--%> +
+
@@ -213,7 +213,21 @@ $('#exampleModal').modal('show'); - $('#customFile').on('change', function() { + fetch("/person/image") + .then(function (response) { + if (response.ok) { + // 图像存在,显示自定义头像 + $('#custom_avatar').show(); + } else { + // 图像不存在,显示默认头像 + $('#default_avatar').show(); + } + }) + .catch(function (error) { + console.log("请求失败:", error); + }); + + $('#customFile').on('change', function () { var file = this.files[0]; // 获取选择的文件 // 检查是否选择了文件 @@ -233,12 +247,12 @@ data: formData, processData: false, // 告诉jQuery不要处理FormData对象 contentType: false, // 告诉jQuery不要设置Content-Type请求头 - success: function(response) { - // 成功上传后的操作 + success: function () { $('#default_avatar').hide(); // 隐藏默认头像 - $('#custom_avatar').attr('src', response.avatarUrl).show(); // 更新自定义头像的图像源 + $('#custom_avatar').show(); // 显示自定义头像 + $('#note').show(); // 显示提示消息 }, - error: function(xhr, status, error) { + error: function (xhr, status, error) { console.log('上传失败:', error); alert('上传失败,请重试'); }