{"id":64483,"date":"2026-01-23T16:48:33","date_gmt":"2026-01-23T08:48:33","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/64483.html"},"modified":"2026-01-23T16:48:33","modified_gmt":"2026-01-23T08:48:33","slug":"%e7%9f%a5%e5%85%89%e9%a1%b9%e7%9b%ae%e7%94%a8%e6%88%b7%e8%b5%84%e6%96%99%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/64483.html","title":{"rendered":"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757"},"content":{"rendered":"<p id=\"ua902284a\">\u524d\u8a00&#xff1a;<\/p>\n<p id=\"u07328a31\">\u8be5\u6587\u6863\u53ea\u4f5c\u4e3a\u672c\u4eba\u5b66\u4e60\u8fc7\u7a0b\u7684\u8bb0\u5f55&#xff0c;\u82e5\u8fd8\u9700\u8981\u66f4\u8be6\u7ec6\u7684\u9879\u76ee\u6587\u6863\u53ef\u4ee5\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u8fdb\u884c\u8d2d\u4e70<\/p>\n<p id=\"ubdd24c31\">\u6587\u6863\u5730\u5740<\/p>\n<p id=\"u701cfb9c\">\u540c\u65f6\u8be5\u9879\u76ee\u5df2\u7ecf\u5728git\u4e0a\u9762\u5f00\u6e90&#xff0c;\u53ef\u4ee5\u5728\u8d2d\u4e70\u524d\u53bb\u770b\u4e00\u4e0b\u8be5\u9879\u76ee\u3002<\/p>\n<p id=\"ub970156f\">\u9879\u76ee\u540e\u7aef\u7684git\u5730\u5740&#xff1a;\u77e5\u5149git\u540e\u7aef\u5730\u5740<\/p>\n<p id=\"ue9c6c7b5\">\u9879\u76ee\u524d\u7aef\u7684git\u5730\u5740: \u77e5\u5149git\u524d\u7aef\u5730\u5740<\/p>\n<p id=\"uc49bd63e\">\u7531\u4e8e\u672c\u4eba\u8fd8\u5728\u5f00\u53d1\u5b66\u4e60\u5f53\u4e2d\u5982\u679c\u8981\u770b\u672c\u4eba\u7684\u4ee3\u7801\u53ef\u4ee5\u8fdb\u5165\u4ee5\u4e0b\u5730\u5740&#xff1a;<\/p>\n<p id=\"u486b970e\">\u672c\u4eba\u7684gitee\u5730\u5740<\/p>\n<h2 id=\"fyg0e\">1 \u7528\u6237\u8d44\u6599\u6a21\u5757\u7684\u5b9e\u73b0<\/h2>\n<h3 id=\"mBdYb\">1.1 \u51c6\u5907\u7528\u6237\u8d44\u6599\u6a21\u5757\u6570\u636e\u4f20\u8f93\u9700\u8981\u7684DTO,VO<\/h3>\n<p>\u8be5\u6a21\u5757\u4ee3\u7801\u6211\u8003\u8651\u5230\u8ddf\u7528\u6237\u76f8\u5173&#xff0c;\u56e0\u6b64\u6211\u653e\u5728\u7528\u6237\u6a21\u5757\u4e0b\u7684\u5305\u5185<\/p>\n<p>package com.xiaoce.zhiguang.user.domain.dto;<\/p>\n<p>import jakarta.validation.constraints.PastOrPresent;<br \/>\nimport jakarta.validation.constraints.Pattern;<br \/>\nimport jakarta.validation.constraints.Size;<\/p>\n<p>import java.time.LocalDate;<\/p>\n<p>\/**<br \/>\n * ProfilePatchRequest<br \/>\n * &lt;p&gt;<br \/>\n *  \u7528\u6237\u8d44\u6599\u6a21\u5757\u7684dto<br \/>\n * \u4f5c\u7528\u662f\u5728 \u524d\u7aef&#xff08;App\/\u7f51\u9875&#xff09; \u548c \u540e\u7aef \u4e4b\u95f4\u4f20\u9012\u7528\u6237\u60f3\u8981\u4fee\u6539\u7684\u4e2a\u4eba\u8d44\u6599\u6570\u636e\u3002<br \/>\n *<br \/>\n * &#064;author \u5c0f\u7b56<br \/>\n * &#064;date 2026\/1\/20 16:36<br \/>\n *\/<br \/>\npublic record ProfilePatchRequest(<br \/>\n        &#064;Size(min &#061; 1, max &#061; 64, message &#061; &#034;\u6635\u79f0\u957f\u5ea6\u9700\u5728 1-64 \u4e4b\u95f4&#034;) String nickname,<\/p>\n<p>        &#064;Size(max &#061; 512, message &#061; &#034;\u4e2a\u4eba\u63cf\u8ff0\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc7 512&#034;) String bio,<\/p>\n<p>        &#064;Pattern(regexp &#061; &#034;(?i)MALE|FEMALE|OTHER|UNKNOWN&#034;, message &#061; &#034;\u6027\u522b\u53d6\u503c\u4e3a MALE\/FEMALE\/OTHER\/UNKNOWN&#034;) String gender,<\/p>\n<p>        &#064;PastOrPresent(message &#061; &#034;\u751f\u65e5\u4e0d\u80fd\u665a\u4e8e\u4eca\u5929&#034;) LocalDate birthday,<\/p>\n<p>        &#064;Pattern(regexp &#061; &#034;^[a-zA-Z0-9_]{4,32}$&#034;, message &#061; &#034;\u77e5\u5149\u53f7\u4ec5\u652f\u6301\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf&#xff0c;\u957f\u5ea6 4-32&#034;) String zgId,<\/p>\n<p>        &#064;Size(max &#061; 128, message &#061; &#034;\u5b66\u6821\u540d\u79f0\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc7 128&#034;) String school,<\/p>\n<p>        String tagJson<br \/>\n) {<br \/>\n}<br \/>\npackage com.xiaoce.zhiguang.user.domain.vo;<\/p>\n<p>import com.xiaoce.zhiguang.user.domain.po.Users;<\/p>\n<p>import java.time.LocalDate;<\/p>\n<p>\/**<br \/>\n * ProfileResponse<br \/>\n * &lt;p&gt;<br \/>\n * \u7528\u6237\u8d44\u6599\u54cd\u5e94\u5bf9\u8c61 (VO)<br \/>\n * \u4f5c\u7528&#xff1a;\u540e\u7aef\u5c06\u6570\u636e\u5e93\u4e2d\u7684\u7528\u6237\u4fe1\u606f\u8131\u654f\u3001\u6574\u7406\u540e&#xff0c;\u8fd4\u56de\u7ed9\u524d\u7aef\u5c55\u793a\u3002<br \/>\n * \u5b83\u662f\u7528\u6237\u5728\u201c\u4e2a\u4eba\u4e2d\u5fc3\u201d\u6216\u201c\u4ed6\u4eba\u4e3b\u9875\u201d\u770b\u5230\u7684\u8d44\u6599\u89c6\u56fe\u3002<br \/>\n *<br \/>\n * &#064;author \u5c0f\u7b56<br \/>\n * &#064;date 2026\/1\/20 16:37<br \/>\n *\/<br \/>\npublic record ProfileResponse(<br \/>\n        \/**<br \/>\n         * \u7528\u6237\u552f\u4e00\u6807\u8bc6 ID<br \/>\n         *\/<br \/>\n        Long id,<\/p>\n<p>        \/**<br \/>\n         * \u7528\u6237\u6635\u79f0<br \/>\n         *\/<br \/>\n        String nickname,<\/p>\n<p>        \/**<br \/>\n         * \u5934\u50cf URL \u5730\u5740 (\u901a\u5e38\u662f OSS \u8bbf\u95ee\u94fe\u63a5)<br \/>\n         *\/<br \/>\n        String avatar,<\/p>\n<p>        \/**<br \/>\n         * \u4e2a\u4eba\u7b80\u4ecb\/\u7b7e\u540d<br \/>\n         *\/<br \/>\n        String bio,<\/p>\n<p>        \/**<br \/>\n         * \u77e5\u5149\u53f7 (\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u552f\u4e00\u6807\u8bc6 ID)<br \/>\n         *\/<br \/>\n        String zgId,<\/p>\n<p>        \/**<br \/>\n         * \u6027\u522b (\u5982&#xff1a;MALE, FEMALE, OTHER, UNKNOWN)<br \/>\n         *\/<br \/>\n        String gender,<\/p>\n<p>        \/**<br \/>\n         * \u51fa\u751f\u65e5\u671f<br \/>\n         *\/<br \/>\n        LocalDate birthday,<\/p>\n<p>        \/**<br \/>\n         * \u5b66\u6821\/\u6559\u80b2\u80cc\u666f<br \/>\n         *\/<br \/>\n        String school,<\/p>\n<p>        \/**<br \/>\n         * \u7ed1\u5b9a\u624b\u673a\u53f7 (\u901a\u5e38\u4f1a\u505a\u63a9\u7801\u5904\u7406&#xff0c;\u5982 138****0000)<br \/>\n         *\/<br \/>\n        String phone,<\/p>\n<p>        \/**<br \/>\n         * \u7ed1\u5b9a\u90ae\u7bb1<br \/>\n         *\/<br \/>\n        String email,<\/p>\n<p>        \/**<br \/>\n         * \u7528\u6237\u6807\u7b7e (JSON \u683c\u5f0f\u5b57\u7b26\u4e32)<br \/>\n         *\/<br \/>\n        String tagJson<br \/>\n) {<br \/>\n    \/**<br \/>\n     * \u9759\u6001\u5de5\u5382\u65b9\u6cd5&#xff1a;\u5c06\u6570\u636e\u5e93 PO \u5bf9\u8c61\u5b89\u5168\u5730\u8f6c\u6362\u4e3a\u5c55\u793a\u7528\u7684 VO \u5bf9\u8c61<br \/>\n     * &#064;param user \u6570\u636e\u5e93 Users \u5b9e\u4f53<br \/>\n     * &#064;return \u8f6c\u6362\u540e\u7684 ProfileResponse<br \/>\n     *\/<br \/>\n    public static ProfileResponse fromEntity(Users user) {<br \/>\n        if (user &#061;&#061; null) return null;<br \/>\n        return new ProfileResponse(<br \/>\n                user.getId(),<br \/>\n                user.getNickname(),<br \/>\n                \/\/ \u5982\u679c\u5934\u50cf\u4e3a\u7a7a&#xff0c;\u8fd9\u91cc\u53ef\u4ee5\u5904\u7406\u9ed8\u8ba4\u503c<br \/>\n                user.getAvatar() &#061;&#061; null ?&#034;https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260123084832-697335e02d09f.jpg&#034;  : user.getAvatar(),<br \/>\n                user.getBio(),<br \/>\n                user.getZgId(),<br \/>\n                user.getGender(),<br \/>\n                user.getBirthday(),<br \/>\n                user.getSchool(),<br \/>\n                \/\/ \u5728\u6b64\u5904\u8fdb\u884c\u624b\u673a\u53f7\u8131\u654f\u5904\u7406<br \/>\n                maskPhone(user.getPhone()),<br \/>\n                maskEmail(user.getEmail()),<br \/>\n                user.getTagsJson()<br \/>\n        );<br \/>\n    }<br \/>\n    private static String maskPhone(String phone) {<br \/>\n        if (phone &#061;&#061; null || phone.length() &lt; 11) return phone;<br \/>\n        return phone.replaceAll(&#034;(\\\\\\\\d{3})\\\\\\\\d{4}(\\\\\\\\d{4})&#034;, &#034;$1****$2&#034;);<br \/>\n    }<\/p>\n<p>    private static String maskEmail(String email) {<br \/>\n        if (email &#061;&#061; null || !email.contains(&#034;&#064;&#034;)) return email;<br \/>\n        return email.replaceAll(&#034;(\\\\\\\\w).*(?&#061;&#064;)&#034;, &#034;$1****&#034;);<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"lN37R\">1.2 \u914d\u7f6e\u8de8\u57dfCorsConfig<\/h3>\n<p id=\"u2595e38a\">\u90a3\u8fd9\u662f\u65f6\u5019\u53c8\u6709\u95ee\u9898\u4e86&#xff0c;\u4e4b\u524d\u5728\u914d\u7f6e\u6a21\u5757\u4e2d\u5df2\u7ecf\u6709\u4e86SecurityConfig\u91cc\u9762\u6709\u4e2acorsConfigurationSource\u8fd9\u4e2aBean&#xff0c;\u4e3a\u4ec0\u4e48\u8fd9\u91cc\u53c8\u8981\u6709\u4e2aCorsConfig\u5462&#xff1f;\u80fd\u4e0d\u80fd\u76f4\u63a5\u5728\u8fd9\u4e2acorsConfigurationSource\u91cc\u9762\u505a\u4fee\u6539&#xff0c;\u4e0d\u5199\u914d\u7f6e\u7c7b\u5462&#xff1f;<\/p>\n<ul>\n<li id=\"ufe6bdf9a\">\u7b2c\u4e00\u4e2a\u95ee\u9898\u56de\u7b54&#xff1a;<\/li>\n<\/ul>\n<p id=\"u562a2622\">\u4e3b\u8981\u539f\u56e0\u662f\u56e0\u4e3a\u4f7f\u7528\u4e86PatchMapping\u8bf7\u6c42&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u590d\u6742\u8bf7\u6c42\u4f1a\u89e6\u53d1 CORS \u9884\u68c0&#xff1b;\u4f1a\u5148\u53d1\u9001 OPTIONS \u9884\u68c0\u8bf7\u6c42\u3002\u5982\u679c\u540e\u7aef\u672a\u6b63\u786e\u914d\u7f6e CORS \u6216\u672a\u653e\u884c OPTIONS&#xff0c;\u8bf7\u6c42\u5c31\u4f1a\u88ab\u6d4f\u89c8\u5668\u62e6\u622a&#xff0c;\u63a5\u53e3\u5c31\u65e0\u6cd5\u8bf7\u6c42\u6210\u529f\u3002\u800c\u4e4b\u524d\u7684corsConfigurationSource\u5e76\u672a\u505a\u653e\u884c\u64cd\u4f5c\u3002<\/p>\n<ul>\n<li id=\"u63c1c46d\">\u7b2c\u4e8c\u4e2a\u95ee\u9898\u56de\u7b54<\/li>\n<\/ul>\n<p id=\"u3e0ce414\">\u5982\u679c\u53ea\u7528 SecurityConfig (\u6807\u51c6\u914d\u7f6e)&#xff1a;<\/p>\n<p id=\"u9c9def7c\">Spring Security \u7684\u8fc7\u6ee4\u5668\u94fe\u6761\u662f\u4e25\u683c\u6309\u987a\u5e8f\u6267\u884c\u7684\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b&#xff0c;\u5b83\u7684 \u9274\u6743\u8fc7\u6ee4\u5668 (AuthorizationFilter) \u5f80\u5f80\u6392\u5728 CORS\u8fc7\u6ee4\u5668 \u7684\u524d\u9762\u6216\u8005\u7d27\u6328\u7740\u3002<\/p>\n<li id=\"u0f436e24\">\u8bf7\u6c42\u8fdb\u6765&#xff1a;OPTIONS \u8bf7\u6c42\u5230\u8fbe Spring Security\u3002<\/li>\n<li id=\"u98ed0ef1\">\u5b89\u68c0\u5458&#xff08;Security&#xff09;\u62e6\u4f4f&#xff1a;<\/li>\n<li>\n<li id=\"u3ee0b031\">\u5b89\u68c0\u5458&#xff1a;\u201c\u7ad9\u4f4f&#xff01;\u4f60\u8bbf\u95ee\u7684\u662f API \u63a5\u53e3\u3002\u201d<\/li>\n<li id=\"uab73fae0\">\u5b89\u68c0\u5458&#xff1a;\u201c\u4f60\u7684 Token \u5462&#xff1f;\u201d<\/li>\n<li id=\"ue43c1f8b\">\u5173\u952e\u70b9&#xff1a;\u6d4f\u89c8\u5668\u7684 OPTIONS \u8bf7\u6c42\u901a\u5e38\u662f\u4e0d\u5e26 Token \u7684&#xff01;<\/li>\n<\/li>\n<li id=\"ub0fd3a33\">\u7ed3\u679c&#xff1a;\u5b89\u68c0\u5458\u76f4\u63a5\u6253\u56de \u2014\u2014 401 Unauthorized&#xff08;\u672a\u6388\u6743&#xff09;\u3002<\/li>\n<li id=\"u597b95c6\">CORS \u8fc7\u6ee4\u5668&#xff1a;\u5b83\u539f\u672c\u51c6\u5907\u597d\u4e86\u8bf4\u201c\u884c&#xff0c;\u5141\u8bb8\u8de8\u57df\u201d&#xff0c;\u4f46\u8bf7\u6c42\u8fd8\u6ca1\u8d70\u5230\u5b83\u8fd9\u513f&#xff0c;\u5c31\u88ab\u524d\u9762\u7684\u5b89\u68c0\u5458\u7ed9\u6bd9\u4e86\u3002<\/li>\n<p id=\"ua8fbd110\">\u800c\u5b9a\u4e49\u7684 CorsConfig \u7528\u4e86 Ordered.HIGHEST_PRECEDENCE&#xff0c;\u8fd9\u76f8\u5f53\u4e8e\u628a CORS \u5904\u7406\u63d0\u5230\u4e86\u5b89\u68c0\u95e8\u4e4b\u5916\u3002<\/p>\n<p id=\"uc348edf3\">\u8bf7\u6c42\u8fdb\u6765&#xff1a;OPTIONS \u8bf7\u6c42\u5230\u8fbe\u670d\u52a1\u5668\u3002<\/p>\n<p id=\"u295fbf1d\">\u63a5\u5f85\u5458&#xff08;\u4f60\u7684 CorsConfig&#xff09;&#xff1a;<\/p>\n<ul>\n<li id=\"u0e483d06\">\u5b83\u6392\u5728\u6700\u6700\u524d\u9762&#xff0c;\u751a\u81f3\u5728 Spring Security \u5b89\u68c0\u95e8\u5916\u9762\u3002<\/li>\n<li id=\"u049894b2\">\u63a5\u5f85\u5458&#xff1a;\u201c\u54e6&#xff0c;\u4f60\u662f\u6765\u95ee\u8def\u7684&#xff08;OPTIONS&#xff09;&#xff1f;\u884c&#xff0c;\u6211\u7ed9\u4f60\u76d6\u4e2a\u7ae0&#xff08;Access-Control-Allow-Origin&#xff09;&#xff0c;\u4f60\u8fdb\u53bb\u5427\u3002\u201d<\/li>\n<li id=\"udf5ba46f\">\u76f4\u63a5\u653e\u884c&#xff1a;\u5b83\u76f4\u63a5\u8fd4\u56de 200 OK&#xff0c;\u6216\u8005\u628a\u8bf7\u6c42\u653e\u8fc7\u53bb\u3002<\/li>\n<\/ul>\n<p id=\"u81f39786\">\u5b89\u68c0\u5458&#xff08;Security&#xff09;&#xff1a;<\/p>\n<ul>\n<li id=\"u08111c2c\">\u770b\u5230\u8bf7\u6c42\u5df2\u7ecf\u5904\u7406\u5b8c\u4e86&#xff08;\u6216\u8005\u770b\u5230 OPTIONS \u8bf7\u6c42\u5df2\u7ecf\u6709\u4e86\u5408\u6cd5\u7684 CORS \u5934&#xff09;\u3002<\/li>\n<li id=\"u7850b56b\">Spring Security \u5185\u90e8\u673a\u5236\u53d1\u73b0\u5982\u679c\u662f \u5df2\u7ecf\u5904\u7406\u8fc7\u7684 CORS \u9884\u68c0\u8bf7\u6c42&#xff0c;\u5f80\u5f80\u5c31\u4f1a\u76f4\u63a5\u653e\u8fc7&#xff0c;\u4e0d\u518d\u67e5 Token\u3002<\/li>\n<\/ul>\n<p>package com.xiaoce.zhiguang.user.config;<\/p>\n<p>import org.springframework.boot.web.servlet.FilterRegistrationBean;<br \/>\nimport org.springframework.context.annotation.Bean;<br \/>\nimport org.springframework.context.annotation.Configuration;<br \/>\nimport org.springframework.core.Ordered;<br \/>\nimport org.springframework.web.cors.CorsConfiguration;<br \/>\nimport org.springframework.web.cors.UrlBasedCorsConfigurationSource;<br \/>\nimport org.springframework.web.filter.CorsFilter;<\/p>\n<p>import java.util.List;<\/p>\n<p>\/**<br \/>\n * CorsConfig<br \/>\n * &lt;p&gt;<br \/>\n * \u5168\u5c40\u8de8\u57df\u914d\u7f6e\u7c7b<br \/>\n * \u91c7\u7528 Filter \u65b9\u6848&#xff0c;\u5728\u8bf7\u6c42\u8fdb\u5165 Servlet \u4e4b\u524d\u5904\u7406 CORS&#xff0c;\u4f18\u5148\u7ea7\u9ad8\u4e8e Spring Security<br \/>\n * &#064;author \u5c0f\u7b56<br \/>\n * &#064;date 2026\/1\/20 18:05<br \/>\n *\/<br \/>\n&#064;Configuration<br \/>\npublic class CorsConfig {<br \/>\n    &#064;Bean<br \/>\n    public FilterRegistrationBean&lt;CorsFilter&gt; corsFilterRegistration() {<br \/>\n        \/\/ 1. \u521b\u5efa CORS \u914d\u7f6e\u5bf9\u8c61&#xff0c;\u7528\u4e8e\u5b9a\u4e49\u5177\u4f53\u7684\u8de8\u57df\u89c4\u5219<br \/>\n        CorsConfiguration config &#061; new CorsConfiguration();<\/p>\n<p>        \/\/ \u5141\u8bb8\u7684\u6765\u6e90&#xff1a;\u4f7f\u7528 AllowedOriginPatterns \u652f\u6301\u901a\u914d\u7b26&#xff0c;\u5141\u8bb8\u6240\u6709\u7ad9\u70b9\u8de8\u57df\u8bf7\u6c42<br \/>\n        \/\/ \u6ce8\u610f&#xff1a;\u751f\u4ea7\u73af\u5883\u4e0b\u5efa\u8bae\u8bbe\u7f6e\u4e3a\u5177\u4f53\u7684\u57df\u540d&#xff0c;\u5982 &#034;https:\/\/www.zhiguang.com&#034;<br \/>\n        config.setAllowedOriginPatterns(List.of(&#034;*&#034;));<\/p>\n<p>        \/\/ \u5141\u8bb8\u7684 HTTP \u65b9\u6cd5&#xff1a;\u5fc5\u987b\u5305\u542b OPTIONS \u7528\u4e8e\u5904\u7406\u9884\u68c0\u8bf7\u6c42&#xff0c;PATCH \u7528\u4e8e\u5c40\u90e8\u66f4\u65b0<br \/>\n        config.setAllowedMethods(List.of(&#034;GET&#034;, &#034;POST&#034;, &#034;PUT&#034;, &#034;PATCH&#034;, &#034;DELETE&#034;, &#034;OPTIONS&#034;));<\/p>\n<p>        \/\/ \u5141\u8bb8\u7684\u8bf7\u6c42\u5934&#xff1a;\u5141\u8bb8\u524d\u7aef\u5728 Header \u4e2d\u643a\u5e26 Authorization (\u5b58\u653e JWT) \u548c Content-Type \u7b49\u4fe1\u606f<br \/>\n        config.setAllowedHeaders(List.of(&#034;*&#034;));<\/p>\n<p>        \/\/ \u662f\u5426\u5141\u8bb8\u643a\u5e26\u51ed\u8bc1&#xff1a;\u82e5\u524d\u7aef\u9700\u8981\u8de8\u57df\u53d1\u9001 Cookie&#xff0c;\u6b64\u9879\u5fc5\u987b\u4e3a true<br \/>\n        \/\/ \u7531\u4e8e\u672c\u9879\u76ee\u76ee\u524d\u5c06 Refresh Token \u5b58\u5728 localStorage&#xff0c;\u6545\u8bbe\u4e3a false \u5373\u53ef<br \/>\n        config.setAllowCredentials(false);<\/p>\n<p>        \/\/ \u9884\u68c0\u8bf7\u6c42\u7684\u7f13\u5b58\u65f6\u95f4&#xff1a;\u5728\u6b64\u65f6\u95f4\u5185&#xff08;1\u5c0f\u65f6&#xff09;&#xff0c;\u6d4f\u89c8\u5668\u4e0d\u518d\u9488\u5bf9\u76f8\u540c\u63a5\u53e3\u53d1\u9001 OPTIONS \u9884\u68c0&#xff0c;\u63d0\u5347\u6027\u80fd<br \/>\n        config.setMaxAge(3600L);<\/p>\n<p>        \/\/ 2. \u914d\u7f6e\u914d\u7f6e\u6e90&#xff1a;\u5c06\u4e0a\u8ff0\u89c4\u5219\u5e94\u7528\u5230\u5177\u4f53\u7684 URL \u8def\u5f84\u4e0a<br \/>\n        UrlBasedCorsConfigurationSource source &#061; new UrlBasedCorsConfigurationSource();<\/p>\n<p>        \/\/ \u9488\u5bf9 Profile \u6a21\u5757\u53ca Auth \u6a21\u5757\u7b49\u6240\u6709 API \u63a5\u53e3\u5f00\u542f\u8de8\u57df<br \/>\n        source.registerCorsConfiguration(&#034;\/api\/v1\/**&#034;, config);<\/p>\n<p>        \/\/ 3. \u6838\u5fc3&#xff1a;\u521b\u5efa Filter \u6ce8\u518c\u5bf9\u8c61&#xff0c;\u5e76\u8bbe\u7f6e\u6700\u9ad8\u4f18\u5148\u7ea7<br \/>\n        FilterRegistrationBean&lt;CorsFilter&gt; bean &#061; new FilterRegistrationBean&lt;&gt;(new CorsFilter(source));<\/p>\n<p>        \/\/ \u8bbe\u7f6e\u6267\u884c\u987a\u5e8f\u4e3a\u6700\u9ad8\u4f18\u5148\u7ea7&#xff08;Ordered.HIGHEST_PRECEDENCE&#xff09;<br \/>\n        \/\/ \u786e\u4fdd\u8de8\u57df\u5904\u7406\u53d1\u751f\u5728 Spring Security \u6743\u9650\u62e6\u622a\u4e4b\u524d&#xff0c;\u5f7b\u5e95\u89e3\u51b3\u9884\u68c0\u8bf7\u6c42\u88ab\u62e6\u622a\u7684\u95ee\u9898<br \/>\n        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);<\/p>\n<p>        return bean;<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"MiF9L\">1.3 \u7528\u6237\u8d44\u6599\u6a21\u5757\u7684\u63a5\u53e3\u6587\u6863<\/h3>\n<p id=\"u78dc2d5e\">\u63a5\u53e3\u8be6\u60c5<\/p>\n<p id=\"ud04f0100\">1.1 \u5c40\u90e8\u66f4\u65b0\u4e2a\u4eba\u8d44\u6599<\/p>\n<p id=\"ud33db6ac\">\u91c7\u7528 PATCH \u8bed\u4e49&#xff0c;\u4ec5\u63d0\u4ea4\u9700\u8981\u4fee\u6539\u7684\u5b57\u6bb5\u3002\u672a\u63d0\u4ea4\u7684\u5b57\u6bb5\u5728\u6570\u636e\u5e93\u4e2d\u4fdd\u6301\u4e0d\u53d8\u3002<\/p>\n<ul>\n<li id=\"u6561d4a9\">URL: \/<\/li>\n<li id=\"uac89a659\">Method: PATCH<\/li>\n<li id=\"ua2578046\">\u6743\u9650: \u9700\u8981\u8ba4\u8bc1 (\u9700\u5728 Header \u643a\u5e26 Authorization: Bearer &lt;token&gt;)<\/li>\n<li id=\"uba752d26\">\u8bf7\u6c42\u5934: Content-Type: application\/json<\/li>\n<\/ul>\n<p id=\"u2062cb1c\">\u8bf7\u6c42\u53c2\u6570 (Body):<\/p>\n<ul>\n<li id=\"u4b2be541\">nickname (String, \u9009\u586b): \u7528\u6237\u6635\u79f0&#xff0c;\u957f\u5ea6 1-64\u3002<\/li>\n<li id=\"u74733e90\">bio (String, \u9009\u586b): \u4e2a\u4eba\u63cf\u8ff0&#xff0c;\u957f\u5ea6\u4e0d\u8d85\u8fc7 512\u3002<\/li>\n<li id=\"u8fc8a2ef\">gender (String, \u9009\u586b): \u6027\u522b&#xff0c;\u53d6\u503c\u4e3a MALE, FEMALE, OTHER, UNKNOWN&#xff08;\u5ffd\u7565\u5927\u5c0f\u5199&#xff09;\u3002<\/li>\n<li id=\"u54601807\">birthday (LocalDate, \u9009\u586b): \u751f\u65e5&#xff0c;\u683c\u5f0f yyyy-MM-dd&#xff0c;\u4e0d\u80fd\u665a\u4e8e\u4eca\u5929\u3002<\/li>\n<li id=\"u48c6e83b\">zgId (String, \u9009\u586b): \u77e5\u5149\u53f7&#xff0c;\u4ec5\u652f\u6301\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf&#xff0c;\u957f\u5ea6 4-32\u3002<\/li>\n<li id=\"udce21d8a\">school (String, \u9009\u586b): \u5b66\u6821\u540d\u79f0&#xff0c;\u957f\u5ea6\u4e0d\u8d85\u8fc7 128\u3002<\/li>\n<li id=\"u843bd83f\">tagJson (String, \u9009\u586b): \u7528\u6237\u6807\u7b7e\u7684 JSON \u683c\u5f0f\u5b57\u7b26\u4e32\u3002<\/li>\n<\/ul>\n<p id=\"ud5368819\">\u54cd\u5e94\u793a\u4f8b (200 OK):<\/p>\n<p id=\"ucadffa49\">JSON<\/p>\n<p>{<br \/>\n  &#034;id&#034;: 10086,<br \/>\n  &#034;nickname&#034;: &#034;\u5c0f\u7b56&#034;,<br \/>\n  &#034;avatar&#034;: &#034;https:\/\/oss&#8230;\/avatar.jpg&#034;,<br \/>\n  &#034;bio&#034;: &#034;\u5199\u4ee3\u7801\u7684&#034;,<br \/>\n  &#034;zgId&#034;: &#034;xiaoce_001&#034;,<br \/>\n  &#034;gender&#034;: &#034;MALE&#034;,<br \/>\n  &#034;birthday&#034;: &#034;2000-01-01&#034;,<br \/>\n  &#034;school&#034;: &#034;\u8d64\u5cf0\u5b66\u9662&#034;,<br \/>\n  &#034;phone&#034;: &#034;138****8888&#034;,<br \/>\n  &#034;email&#034;: &#034;x****&#064;example.com&#034;,<br \/>\n  &#034;tagJson&#034;: &#034;[\\\\&#034;Java\\\\&#034;, \\\\&#034;\u540e\u7aef\\\\&#034;]&#034;<br \/>\n} <\/p>\n<hr id=\"ik2it\" \/>\n<p id=\"u41d8c076\">1.2 \u66f4\u65b0\u7528\u6237\u5934\u50cf<\/p>\n<p id=\"u7e1a3088\">\u4e0a\u4f20\u56fe\u7247\u6587\u4ef6&#xff0c;\u540e\u7aef\u4f1a\u5c06\u5176\u5b58\u5165 OSS \u5e76\u81ea\u52a8\u540c\u6b65\u66f4\u65b0\u7528\u6237\u8868\u4e2d\u7684\u5934\u50cf\u5730\u5740\u3002<\/p>\n<ul>\n<li id=\"u4a235870\">URL: \/avatar<\/li>\n<li id=\"ub3965e11\">Method: POST<\/li>\n<li id=\"ue5fac626\">\u6743\u9650: \u9700\u8981\u8ba4\u8bc1<\/li>\n<li id=\"u506bde0c\">\u8bf7\u6c42\u5934: Content-Type: multipart\/form-data<\/li>\n<\/ul>\n<p id=\"u1d0a78b3\">\u8bf7\u6c42\u53c2\u6570 (Form-Data):<\/p>\n<ul>\n<li id=\"u9bdf195b\">file (File, \u5fc5\u586b): \u5934\u50cf\u56fe\u7247\u6587\u4ef6\u6d41&#xff08;\u901a\u5e38\u9650\u5236\u4e3a jpg\/png \u683c\u5f0f&#xff09;\u3002<\/li>\n<\/ul>\n<p id=\"ud02d3e8a\">\u54cd\u5e94\u793a\u4f8b (200 OK):<\/p>\n<p id=\"u3f1ec9a6\">JSON<\/p>\n<p>{<br \/>\n  &#034;id&#034;: 10086,<br \/>\n  &#034;nickname&#034;: &#034;\u5c0f\u7b56&#034;,<br \/>\n  &#034;avatar&#034;: &#034;https:\/\/oss-cn-shenzhen&#8230;\/new_avatar_uuid.png&#034;,<br \/>\n  &#034;bio&#034;: &#034;\u5199\u4ee3\u7801\u7684&#034;,<br \/>\n  &#8230;<br \/>\n} <\/p>\n<h3 id=\"Ri5TW\">1.4 \u7528\u6237\u8d44\u6599\u6a21\u5757controller\u5c42\u5b9e\u73b0<\/h3>\n<p>package com.xiaoce.zhiguang.user.controller;<\/p>\n<p>import com.xiaoce.zhiguang.Oss.service.Impl.OssStorageServiceImpl;<br \/>\nimport com.xiaoce.zhiguang.auth.service.impl.JwtServiceImpl;<br \/>\nimport com.xiaoce.zhiguang.user.domain.dto.ProfilePatchRequest;<br \/>\nimport com.xiaoce.zhiguang.user.domain.vo.ProfileResponse;<br \/>\nimport com.xiaoce.zhiguang.user.service.IUserProfileService;<br \/>\nimport io.swagger.v3.oas.annotations.Operation;<br \/>\nimport io.swagger.v3.oas.annotations.Parameter;<br \/>\nimport io.swagger.v3.oas.annotations.media.Content;<br \/>\nimport io.swagger.v3.oas.annotations.media.Schema;<br \/>\nimport io.swagger.v3.oas.annotations.responses.ApiResponse;<br \/>\nimport io.swagger.v3.oas.annotations.responses.ApiResponses;<br \/>\nimport io.swagger.v3.oas.annotations.tags.Tag;<br \/>\nimport jakarta.validation.Valid;<br \/>\nimport lombok.RequiredArgsConstructor;<br \/>\nimport org.springframework.http.MediaType;<br \/>\nimport org.springframework.security.core.annotation.AuthenticationPrincipal;<br \/>\nimport org.springframework.security.oauth2.jwt.Jwt;<br \/>\nimport org.springframework.validation.annotation.Validated;<br \/>\nimport org.springframework.web.bind.annotation.*;<br \/>\nimport org.springframework.web.multipart.MultipartFile;<\/p>\n<p>\/**<br \/>\n * ProfileController<br \/>\n * &lt;p&gt;<br \/>\n * \u7528\u6237\u7b80\u4ecb\u76f8\u5173\u4e1a\u52a1\u7684controller<br \/>\n *<br \/>\n * &#064;author \u5c0f\u7b56<br \/>\n * &#064;date 2026\/1\/20 16:44<br \/>\n *\/<br \/>\n&#064;RestController<br \/>\n&#064;Tag(name &#061; &#034;\u7528\u6237\u7b80\u4ecb\u6a21\u5757&#034;)<br \/>\n&#064;RequestMapping(&#034;\/api\/v1\/profile&#034;)<br \/>\n&#064;Validated<br \/>\n&#064;RequiredArgsConstructor<br \/>\npublic class ProfileController {<\/p>\n<p>    private final IUserProfileService profileService;<br \/>\n    private final JwtServiceImpl jwtService;<br \/>\n    private final OssStorageServiceImpl ossStorageService;<\/p>\n<p>    \/**<br \/>\n     * ATCH (\u5c40\u90e8\u4fee\u6539)<br \/>\n     * \u64cd\u4f5c\u76ee\u6807: \u8d44\u6e90\u7684\u90e8\u5206\u5b57\u6bb5<br \/>\n     * \u63d0\u4ea4\u8981\u6c42: \u53ea\u9700\u63d0\u4ea4\u60f3\u4fee\u6539\u7684\u5b57\u6bb5<br \/>\n     * \u5e42\u7b49\u6027: \u901a\u5e38\u4e0d\u5e42\u7b49&#xff08;\u53d6\u51b3\u4e8e\u5177\u4f53\u5b9e\u73b0&#xff09;<br \/>\n     * \u4f7f\u7528\u573a\u666f: \u53ea\u9700\u8981\u53d1\u4e00\u4e2a\u5934\u50cf URL \u6216\u6587\u4ef6\u5373\u53ef<br \/>\n     *\/<\/p>\n<p>    &#064;PatchMapping<br \/>\n    &#064;Operation(<br \/>\n            summary &#061; &#034;\u5c40\u90e8\u66f4\u65b0\u4e2a\u4eba\u8d44\u6599&#034;,<br \/>\n            description &#061; &#034;\u91c7\u7528 PATCH \u8bed\u4e49&#xff0c;\u4ec5\u63d0\u4ea4\u9700\u8981\u4fee\u6539\u7684\u5b57\u6bb5&#xff08;\u5982\u6635\u79f0\u3001\u7b80\u4ecb\u7b49&#xff09;\u3002\u672a\u63d0\u4ea4\u7684\u5b57\u6bb5\u5728\u6570\u636e\u5e93\u4e2d\u4fdd\u6301\u4e0d\u53d8\u3002&#034;<br \/>\n    )<br \/>\n    &#064;ApiResponses({<br \/>\n            &#064;ApiResponse(responseCode &#061; &#034;200&#034;, description &#061; &#034;\u66f4\u65b0\u6210\u529f&#034;,<br \/>\n                    content &#061; &#064;Content(schema &#061; &#064;Schema(implementation &#061; ProfileResponse.class))),<br \/>\n            &#064;ApiResponse(responseCode &#061; &#034;400&#034;, description &#061; &#034;\u53c2\u6570\u6821\u9a8c\u5931\u8d25\u6216\u4e1a\u52a1\u903b\u8f91\u9519\u8bef&#034;),<br \/>\n            &#064;ApiResponse(responseCode &#061; &#034;401&#034;, description &#061; &#034;\u672a\u767b\u5f55\u6216 Token \u65e0\u6548&#034;)<br \/>\n    })<br \/>\n    public ProfileResponse patch(&#064;AuthenticationPrincipal Jwt jwt,<br \/>\n                                 &#064;Valid &#064;RequestBody ProfilePatchRequest request) {<br \/>\n        long userId &#061; jwtService.extractUserId(jwt);<br \/>\n        return profileService.updateProfile(userId, request);<br \/>\n    }<\/p>\n<p>    &#064;PostMapping(value &#061; &#034;\/avatar&#034;, consumes &#061; MediaType.MULTIPART_FORM_DATA_VALUE)<br \/>\n    &#064;Operation(<br \/>\n            summary &#061; &#034;\u66f4\u65b0\u7528\u6237\u5934\u50cf&#034;,<br \/>\n            description &#061; &#034;\u4e0a\u4f20\u56fe\u7247\u6587\u4ef6&#xff0c;\u540e\u7aef\u4f1a\u5c06\u5176\u5b58\u5165 OSS \u5e76\u540c\u6b65\u66f4\u65b0\u7528\u6237\u8868\u4e2d\u7684\u5934\u50cf\u5730\u5740\u3002\u6ce8\u610f&#xff1a;\u8bf7\u6c42\u5934\u9700\u8bbe\u4e3a multipart\/form-data\u3002&#034;<br \/>\n    )<br \/>\n    &#064;ApiResponses({<br \/>\n            &#064;ApiResponse(responseCode &#061; &#034;200&#034;, description &#061; &#034;\u66f4\u65b0\u6210\u529f&#034;,<br \/>\n                    content &#061; &#064;Content(schema &#061; &#064;Schema(implementation &#061; ProfileResponse.class))),<br \/>\n            &#064;ApiResponse(responseCode &#061; &#034;400&#034;, description &#061; &#034;\u6587\u4ef6\u8bfb\u53d6\u5931\u8d25\u6216\u683c\u5f0f\u4e0d\u6b63\u786e&#034;)<br \/>\n    })<br \/>\n    public ProfileResponse updateAvatar(<br \/>\n            &#064;AuthenticationPrincipal Jwt jwt,<br \/>\n            &#064;Parameter(description &#061; &#034;\u5934\u50cf\u6587\u4ef6\u6d41&#034;, required &#061; true) &#064;RequestPart(&#034;file&#034;) MultipartFile file<br \/>\n    ) {<br \/>\n        long userId &#061; jwtService.extractUserId(jwt);<br \/>\n        \/\/ 1. \u8c03\u7528 OSS \u57fa\u7840\u6a21\u5757\u4e0a\u4f20\u6587\u4ef6\u5e76\u83b7\u53d6 URL<br \/>\n        String url &#061; ossStorageService.updateAvatar(userId, file);<br \/>\n        \/\/ 2. \u8c03\u7528\u7528\u6237\u4e1a\u52a1\u6a21\u5757\u66f4\u65b0\u6570\u636e\u5e93<br \/>\n        return  profileService.updateAvatar(userId, url);<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"ottdK\">1.5 \u7528\u6237\u8d44\u6599\u6a21\u5757IUserProfileService\u63a5\u53e3\u5b9e\u73b0<\/h3>\n<p>package com.xiaoce.zhiguang.user.service;<\/p>\n<p>import com.baomidou.mybatisplus.extension.service.IService;<br \/>\nimport com.xiaoce.zhiguang.user.domain.dto.ProfilePatchRequest;<br \/>\nimport com.xiaoce.zhiguang.user.domain.po.Users;<br \/>\nimport com.xiaoce.zhiguang.user.domain.vo.ProfileResponse;<br \/>\nimport jakarta.validation.Valid;<\/p>\n<p>\/**<br \/>\n * IUserProfileService<br \/>\n * &lt;p&gt;<br \/>\n * \u7528\u6237\u7b80\u4ecb\u76f8\u5173\u4e1a\u52a1\u63a5\u53e3<br \/>\n *<br \/>\n * &#064;author \u5c0f\u7b56<br \/>\n * &#064;date 2026\/1\/20 16:46<br \/>\n *\/<br \/>\npublic interface IUserProfileService  extends IService&lt;Users&gt; {<\/p>\n<p>    ProfileResponse updateProfile(long userId, &#064;Valid ProfilePatchRequest request);<\/p>\n<p>    ProfileResponse updateAvatar(long userId, String url);<br \/>\n} <\/p>\n<h3 id=\"dmD8h\">1.6 \u7528\u6237\u8d44\u6599\u6a21\u5757UserProfileServiceImpl\u5b9e\u73b0<\/h3>\n<h4 id=\"uS2yu\">1.6.1 \u5b9e\u73b0\u903b\u8f91<\/h4>\n<h5 id=\"x0gMj\">1.6.1.1 \u66f4\u65b0\u7528\u6237\u4e2a\u4eba\u8d44\u6599\u5b9e\u73b0\u903b\u8f91<\/h5>\n<p id=\"u8894764a\">\u6682\u65f6\u65e0\u6cd5\u5728\u98de\u4e66\u6587\u6863\u5916\u5c55\u793a\u6b64\u5185\u5bb9<\/p>\n<h5 id=\"SluxI\">1.6.1.2 \u66f4\u65b0\u7528\u6237\u5934\u50cf\u5b9e\u73b0\u903b\u8f91<\/h5>\n<p id=\"ude85bf2d\">\u6682\u65f6\u65e0\u6cd5\u5728\u98de\u4e66\u6587\u6863\u5916\u5c55\u793a\u6b64\u5185\u5bb9<\/p>\n<h4 id=\"HVqjl\" style=\"background-color:transparent\">1.6.2 \u5b9e\u73b0\u4ee3\u7801<\/h4>\n<p>package com.xiaoce.zhiguang.user.service.impl;<\/p>\n<p>import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;<br \/>\nimport com.xiaoce.zhiguang.common.exception.BusinessException;<br \/>\nimport com.xiaoce.zhiguang.common.exception.ErrorCode;<br \/>\nimport com.xiaoce.zhiguang.user.domain.dto.ProfilePatchRequest;<br \/>\nimport com.xiaoce.zhiguang.user.domain.po.Users;<br \/>\nimport com.xiaoce.zhiguang.user.domain.vo.ProfileResponse;<br \/>\nimport com.xiaoce.zhiguang.user.mapper.UsersMapper;<br \/>\nimport com.xiaoce.zhiguang.user.service.IUserProfileService;<br \/>\nimport com.xiaoce.zhiguang.user.service.IUserService;<br \/>\nimport lombok.RequiredArgsConstructor;<br \/>\nimport org.springframework.stereotype.Service;<br \/>\nimport org.springframework.transaction.annotation.Transactional;<br \/>\nimport org.springframework.util.StringUtils;<\/p>\n<p>import java.time.LocalDateTime;<\/p>\n<p>\/**<br \/>\n * UserProfileServiceImpl<br \/>\n * &lt;p&gt;<br \/>\n * \u7528\u6237\u7b80\u4ecb\u76f8\u5173\u4e1a\u52a1\u5b9e\u73b0\u7c7b<br \/>\n *<br \/>\n * &#064;author \u5c0f\u7b56<br \/>\n * &#064;date 2026\/1\/20 16:47<br \/>\n *\/<br \/>\n&#064;Service<br \/>\n&#064;RequiredArgsConstructor<br \/>\npublic class UserProfileServiceImpl extends ServiceImpl&lt;UsersMapper, Users&gt; implements IUserProfileService{<\/p>\n<p>    private final IUserService userService;<\/p>\n<p>\/**<br \/>\n * \u66f4\u65b0\u7528\u6237\u4e2a\u4eba\u8d44\u6599<br \/>\n * &#064;param userId \u7528\u6237ID<br \/>\n * &#064;param request \u5305\u542b\u9700\u8981\u66f4\u65b0\u7684\u4e2a\u4eba\u8d44\u6599\u5b57\u6bb5<br \/>\n * &#064;return ProfileResponse \u66f4\u65b0\u540e\u7684\u7528\u6237\u4e2a\u4eba\u8d44\u6599\u54cd\u5e94\u5bf9\u8c61<br \/>\n * &#064;throws BusinessException \u5f53\u7528\u6237\u4e0d\u5b58\u5728\u6216\u672a\u63d0\u4f9b\u4efb\u4f55\u66f4\u65b0\u5b57\u6bb5\u65f6\u629b\u51fa<br \/>\n *\/<br \/>\n    &#064;Override<br \/>\n    &#064;Transactional<br \/>\n    public ProfileResponse updateProfile(long userId, ProfilePatchRequest request) {<br \/>\n    \/\/ \u6839\u636e\u7528\u6237ID\u67e5\u8be2\u7528\u6237\u4fe1\u606f&#xff0c;\u5982\u679c\u4e0d\u5b58\u5728\u5219\u629b\u51fa\u5f02\u5e38<br \/>\n        Users user &#061; lambdaQuery().eq(Users::getId, userId).oneOpt().orElseThrow(<br \/>\n                () -&gt; new BusinessException(ErrorCode.IDENTIFIER_NOT_FOUND, &#034;\u7528\u6237\u4e0d\u5b58\u5728&#034;));<br \/>\n        \/\/ \u81f3\u5c11\u8981\u63d0\u4ea4\u4e00\u4e2a\u5b57\u6bb5&#xff0c;\u5426\u5219\u5c5e\u4e8e\u65e0\u6548\u8bf7\u6c42<br \/>\n        boolean hasAnyField &#061; request.nickname() !&#061; null || request.bio() !&#061; null || request.gender() !&#061; null<br \/>\n                || request.birthday() !&#061; null || request.zgId() !&#061; null || request.school() !&#061; null<br \/>\n                || request.tagJson() !&#061; null;<br \/>\n        if (!hasAnyField) {<br \/>\n            throw new BusinessException(ErrorCode.BAD_REQUEST, &#034;\u672a\u63d0\u4ea4\u4efb\u4f55\u66f4\u65b0\u5b57\u6bb5&#034;);<br \/>\n        }<br \/>\n        String zgId &#061; user.getZgId();<br \/>\n        if (zgId !&#061; null &amp;&amp; !zgId.isBlank()) {<br \/>\n            userService.existsByZgIdExceptId(zgId, userId);<br \/>\n        }<br \/>\n        \/\/ 2. \u6267\u884c\u52a8\u6001 SQL \u66f4\u65b0<br \/>\n        boolean success &#061; lambdaUpdate()<br \/>\n                .eq(Users::getId, userId) \/\/ \u5b9a\u4f4d\u7528\u6237<br \/>\n                \/\/ \u53ea\u6709\u5f53 request \u4e2d\u7684\u5b57\u6bb5\u4e0d\u4e3a null \u65f6&#xff0c;\u624d\u6267\u884c set \u66f4\u65b0<br \/>\n                .set(request.nickname() !&#061; null, Users::getNickname, request.nickname())<br \/>\n                .set(request.bio() !&#061; null, Users::getBio, request.bio())<br \/>\n                .set(request.gender() !&#061; null, Users::getGender, request.gender())<br \/>\n                .set(request.birthday() !&#061; null, Users::getBirthday, request.birthday())<br \/>\n                .set(request.zgId() !&#061; null, Users::getZgId, request.zgId())<br \/>\n                .set(request.school() !&#061; null, Users::getSchool, request.school())<br \/>\n                .set(request.tagJson() !&#061; null, Users::getTagsJson, request.tagJson())<br \/>\n                .set(Users::getUpdatedAt, LocalDateTime.now()) \/\/ \u8bb0\u5f55\u66f4\u65b0\u65f6\u95f4<br \/>\n                .update();<br \/>\n        if (!success) {<br \/>\n            throw new BusinessException(ErrorCode.INTERNAL_ERROR, &#034;\u4e2a\u4eba\u8d44\u6599\u66f4\u65b0\u5931\u8d25&#034;);<br \/>\n        }<br \/>\n        Users userUpdate &#061; lambdaQuery().eq(Users::getId, userId).oneOpt().orElseThrow(<br \/>\n                () -&gt; new BusinessException(ErrorCode.IDENTIFIER_NOT_FOUND, &#034;\u7528\u6237\u4e0d\u5b58\u5728&#034;));<br \/>\n        return ProfileResponse.fromEntity(userUpdate);<br \/>\n    }<\/p>\n<p>\/**<br \/>\n * \u66f4\u65b0\u7528\u6237\u5934\u50cf\u4fe1\u606f<br \/>\n * \u8be5\u65b9\u6cd5\u4f7f\u7528\u4e8b\u52a1\u6ce8\u89e3&#xff0c;\u786e\u4fdd\u64cd\u4f5c\u7684\u539f\u5b50\u6027<br \/>\n *<br \/>\n * &#064;param userId \u7528\u6237ID<br \/>\n * &#064;param url \u65b0\u7684\u5934\u50cfURL\u5730\u5740<br \/>\n * &#064;return ProfileResponse \u5305\u542b\u66f4\u65b0\u540e\u7528\u6237\u4fe1\u606f\u7684\u54cd\u5e94\u5bf9\u8c61<br \/>\n * &#064;throws BusinessException \u5f53\u7528\u6237\u4e0d\u5b58\u5728\u3001\u5934\u50cf\u94fe\u63a5\u4e3a\u7a7a\u3001\u683c\u5f0f\u4e0d\u5408\u6cd5\u6216\u66f4\u65b0\u5931\u8d25\u65f6\u629b\u51fa<br \/>\n *\/<br \/>\n    &#064;Override<br \/>\n    &#064;Transactional<br \/>\n    public ProfileResponse updateAvatar(long userId, String url) {<br \/>\n    \/\/ \u6839\u636e\u7528\u6237ID\u67e5\u8be2\u7528\u6237\u4fe1\u606f&#xff0c;\u5982\u679c\u7528\u6237\u4e0d\u5b58\u5728\u5219\u629b\u51fa\u5f02\u5e38<br \/>\n        Users user &#061; lambdaQuery().eq(Users::getId, userId).oneOpt().orElseThrow(() -&gt;<br \/>\n                new BusinessException(ErrorCode.IDENTIFIER_NOT_FOUND, &#034;\u7528\u6237\u4e0d\u5b58\u5728&#034;));<br \/>\n    \/\/ \u68c0\u67e5\u5934\u50cf\u94fe\u63a5\u662f\u5426\u4e3a\u7a7a<br \/>\n        if (!StringUtils.hasText(url)) {<br \/>\n            throw new BusinessException(ErrorCode.BAD_REQUEST, &#034;\u5934\u50cf\u94fe\u63a5\u4e0d\u80fd\u4e3a\u7a7a&#034;);<br \/>\n        }<br \/>\n        \/\/ \u7b80\u5355\u7684\u6b63\u5219&#xff1a;\u5fc5\u987b\u4ee5 http(s) \u5f00\u5934&#xff0c;\u901a\u5e38\u4ee5\u5e38\u89c1\u56fe\u7247\u540e\u7f00\u7ed3\u675f<br \/>\n        String regex &#061; &#034;^(https?|ftp):\/\/[^\\\\\\\\s\/$.?#].[^\\\\\\\\s]*$&#034;;<br \/>\n        if (!url.matches(regex)) {<br \/>\n            throw new BusinessException(ErrorCode.BAD_REQUEST, &#034;\u5934\u50cf\u94fe\u63a5\u683c\u5f0f\u4e0d\u5408\u6cd5&#034;);<br \/>\n        }<br \/>\n        boolean success &#061; lambdaUpdate().eq(Users::getId, userId).set(Users::getAvatar, url).update();<br \/>\n        if (!success) {<br \/>\n            throw new BusinessException(ErrorCode.INTERNAL_ERROR, &#034;\u5934\u50cf\u66f4\u65b0\u5931\u8d25&#034;);<br \/>\n        }<br \/>\n        Users userUpdate &#061; this.getBaseMapper().selectById(user.getId());<br \/>\n        return ProfileResponse.fromEntity(userUpdate);<br \/>\n    }<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00&#xff1a;<br \/>\n\u8be5\u6587\u6863\u53ea\u4f5c\u4e3a\u672c\u4eba\u5b66\u4e60\u8fc7\u7a0b\u7684\u8bb0\u5f55&#xff0c;\u82e5\u8fd8\u9700\u8981\u66f4\u8be6\u7ec6\u7684\u9879\u76ee\u6587\u6863\u53ef\u4ee5\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u8fdb\u884c\u8d2d\u4e70<br \/>\n\u6587\u6863\u5730\u5740<br \/>\n\u540c\u65f6\u8be5\u9879\u76ee\u5df2\u7ecf\u5728git\u4e0a\u9762\u5f00\u6e90&#xff0c;\u53ef\u4ee5\u5728\u8d2d\u4e70\u524d\u53bb\u770b\u4e00\u4e0b\u8be5\u9879\u76ee\u3002<br \/>\n\u9879\u76ee\u540e\u7aef\u7684git\u5730\u5740&#xff1a;\u77e5\u5149git\u540e\u7aef\u5730\u5740<br \/>\n\u9879\u76ee\u524d\u7aef\u7684git\u5730\u5740: \u77e5\u5149git\u524d\u7aef\u5730\u5740<br \/>\n\u7531\u4e8e\u672c\u4eba\u8fd8\u5728\u5f00\u53d1\u5b66\u4e60\u5f53\u4e2d\u5982\u679c\u8981\u770b\u672c\u4eba\u7684\u4ee3\u7801\u53ef\u4ee5\u8fdb\u5165\u4ee5\u4e0b\u5730\u5740&#xff1a;<br \/>\n\u672c\u4eba\u7684gitee\u5730\u5740<br \/>\n1 \u7528\u6237\u8d44\u6599\u6a21\u5757\u7684\u5b9e\u73b0<br \/>\n1.1 \u51c6\u5907\u7528\u6237\u8d44\u6599\u6a21\u5757\u6570\u636e\u4f20\u8f93\u9700\u8981<\/p>\n","protected":false},"author":2,"featured_media":64482,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,1769,101,292],"topic":[],"class_list":["post-64483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-mybatis","tag-spring","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/64483.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00&#xff1a; \u8be5\u6587\u6863\u53ea\u4f5c\u4e3a\u672c\u4eba\u5b66\u4e60\u8fc7\u7a0b\u7684\u8bb0\u5f55&#xff0c;\u82e5\u8fd8\u9700\u8981\u66f4\u8be6\u7ec6\u7684\u9879\u76ee\u6587\u6863\u53ef\u4ee5\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u8fdb\u884c\u8d2d\u4e70 \u6587\u6863\u5730\u5740 \u540c\u65f6\u8be5\u9879\u76ee\u5df2\u7ecf\u5728git\u4e0a\u9762\u5f00\u6e90&#xff0c;\u53ef\u4ee5\u5728\u8d2d\u4e70\u524d\u53bb\u770b\u4e00\u4e0b\u8be5\u9879\u76ee\u3002 \u9879\u76ee\u540e\u7aef\u7684git\u5730\u5740&#xff1a;\u77e5\u5149git\u540e\u7aef\u5730\u5740 \u9879\u76ee\u524d\u7aef\u7684git\u5730\u5740: \u77e5\u5149git\u524d\u7aef\u5730\u5740 \u7531\u4e8e\u672c\u4eba\u8fd8\u5728\u5f00\u53d1\u5b66\u4e60\u5f53\u4e2d\u5982\u679c\u8981\u770b\u672c\u4eba\u7684\u4ee3\u7801\u53ef\u4ee5\u8fdb\u5165\u4ee5\u4e0b\u5730\u5740&#xff1a; \u672c\u4eba\u7684gitee\u5730\u5740 1 \u7528\u6237\u8d44\u6599\u6a21\u5757\u7684\u5b9e\u73b0 1.1 \u51c6\u5907\u7528\u6237\u8d44\u6599\u6a21\u5757\u6570\u636e\u4f20\u8f93\u9700\u8981\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/64483.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-23T08:48:33+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64483.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/64483.html\",\"name\":\"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-23T08:48:33+00:00\",\"dateModified\":\"2026-01-23T08:48:33+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/64483.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/64483.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64483.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/64483.html","og_locale":"zh_CN","og_type":"article","og_title":"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00&#xff1a; \u8be5\u6587\u6863\u53ea\u4f5c\u4e3a\u672c\u4eba\u5b66\u4e60\u8fc7\u7a0b\u7684\u8bb0\u5f55&#xff0c;\u82e5\u8fd8\u9700\u8981\u66f4\u8be6\u7ec6\u7684\u9879\u76ee\u6587\u6863\u53ef\u4ee5\u70b9\u51fb\u4e0b\u65b9\u94fe\u63a5\u8fdb\u884c\u8d2d\u4e70 \u6587\u6863\u5730\u5740 \u540c\u65f6\u8be5\u9879\u76ee\u5df2\u7ecf\u5728git\u4e0a\u9762\u5f00\u6e90&#xff0c;\u53ef\u4ee5\u5728\u8d2d\u4e70\u524d\u53bb\u770b\u4e00\u4e0b\u8be5\u9879\u76ee\u3002 \u9879\u76ee\u540e\u7aef\u7684git\u5730\u5740&#xff1a;\u77e5\u5149git\u540e\u7aef\u5730\u5740 \u9879\u76ee\u524d\u7aef\u7684git\u5730\u5740: \u77e5\u5149git\u524d\u7aef\u5730\u5740 \u7531\u4e8e\u672c\u4eba\u8fd8\u5728\u5f00\u53d1\u5b66\u4e60\u5f53\u4e2d\u5982\u679c\u8981\u770b\u672c\u4eba\u7684\u4ee3\u7801\u53ef\u4ee5\u8fdb\u5165\u4ee5\u4e0b\u5730\u5740&#xff1a; \u672c\u4eba\u7684gitee\u5730\u5740 1 \u7528\u6237\u8d44\u6599\u6a21\u5757\u7684\u5b9e\u73b0 1.1 \u51c6\u5907\u7528\u6237\u8d44\u6599\u6a21\u5757\u6570\u636e\u4f20\u8f93\u9700\u8981","og_url":"https:\/\/www.wsisp.com\/helps\/64483.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-23T08:48:33+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/64483.html","url":"https:\/\/www.wsisp.com\/helps\/64483.html","name":"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-23T08:48:33+00:00","dateModified":"2026-01-23T08:48:33+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/64483.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/64483.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/64483.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u77e5\u5149\u9879\u76ee\u7528\u6237\u8d44\u6599\u6a21\u5757"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=64483"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/64482"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=64483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=64483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=64483"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=64483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}