{"id":38443,"date":"2025-05-20T13:02:38","date_gmt":"2025-05-20T05:02:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38443.html"},"modified":"2025-05-20T13:02:38","modified_gmt":"2025-05-20T05:02:38","slug":"%e5%be%ae%e6%9c%8d%e5%8a%a1%e9%a1%b9%e7%9b%ae-%ef%bc%9e%e5%9c%a8%e7%ba%bfoj%e7%b3%bb%e7%bb%9fjava%e7%89%88-4","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38443.html","title":{"rendered":"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4)"},"content":{"rendered":"<p style=\"text-align:center\"><span style=\"color:#fe2c24\">\u76f8\u4fe1\u81ea\u5df1,\u7ec8\u4f1a\u6210\u529f<\/span><\/p>\n<p style=\"text-align:center\"><span style=\"color:#fe2c24\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"359\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520050237-682c0ced13239.jpg\" width=\"287\" \/><\/span><\/p>\n<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"B%E7%AB%AF%E7%94%A8%E6%88%B7%E7%AE%A1%E7%90%86-toc\" style=\"margin-left:40px\">B\u7aef\u7528\u6237\u7ba1\u7406<\/p>\n<p id=\"C%E7%AB%AF%E7%94%A8%E6%88%B7%E4%BB%A3%E7%A0%81-toc\" style=\"margin-left:40px\">C\u7aef\u7528\u6237\u4ee3\u7801<\/p>\n<p id=\"%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81%3A-toc\" style=\"margin-left:80px\">\u53d1\u9001\u9a8c\u8bc1\u7801:<\/p>\n<p id=\"%E9%AA%8C%E8%AF%81%E9%AA%8C%E8%AF%81%E7%A0%81-toc\" style=\"margin-left:80px\">\u9a8c\u8bc1\u9a8c\u8bc1\u7801<\/p>\n<p id=\"%E9%80%80%E5%87%BA%E7%99%BB%E5%BD%95-toc\" style=\"margin-left:80px\">\u9000\u51fa\u767b\u5f55<\/p>\n<p id=\"%E7%99%BB%E5%BD%95%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%E5%8A%9F%E8%83%BD-toc\" style=\"margin-left:80px\">\u767b\u5f55\u7528\u6237\u4fe1\u606f\u529f\u80fd<\/p>\n<p id=\"%C2%A0%E7%94%A8%E6%88%B7%E8%AF%A6%E6%83%85%E4%B8%8E%E7%94%A8%E6%88%B7%E7%BC%96%E8%BE%91-toc\" style=\"margin-left:80px\">\u00a0\u7528\u6237\u8be6\u60c5\u4e0e\u7528\u6237\u7f16\u8f91<\/p>\n<p id=\"%C2%A0%E7%94%A8%E6%88%B7%E7%AB%9E%E8%B5%9B%E6%8E%A5%E5%8F%A3-toc\" style=\"margin-left:40px\">\u00a0\u7528\u6237\u7ade\u8d5b\u63a5\u53e3<\/p>\n<p id=\"%E7%94%A8%E6%88%B7%E6%8A%A5%E5%90%8D%E7%AB%9E%E8%B5%9B-toc\" style=\"margin-left:80px\">\u7528\u6237\u62a5\u540d\u7ade\u8d5b<\/p>\n<p id=\"%E7%94%A8%E6%88%B7%E7%AB%9E%E8%B5%9B%E6%8A%A5%E5%90%8D%E6%8E%A5%E5%8F%A3%E6%9F%A5%E8%AF%A2-toc\" style=\"margin-left:80px\">\u7528\u6237\u7ade\u8d5b\u62a5\u540d\u63a5\u53e3\u67e5\u8be2<\/p>\n<p id=\"%C2%A0%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%E5%88%97%E8%A1%A8-toc\" style=\"margin-left:40px\">\u00a0\u7528\u6237\u4fe1\u606f\u5217\u8868<\/p>\n<p id=\"ThreadLocalUtil-toc\" style=\"margin-left:80px\">ThreadLocalUtil<\/p>\n<p id=\"Hutool%E5%B7%A5%E5%85%B7%E5%BA%93-toc\" style=\"margin-left:40px\">Hutool\u5de5\u5177\u5e93<\/p>\n<p id=\"%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD%E4%BB%8B%E7%BB%8D%C2%A0-toc\" style=\"margin-left:80px\">\u5e38\u7528\u529f\u80fd\u4ecb\u7ecd\u00a0<\/p>\n<hr id=\"hr-toc\" \/>\n<h3>B\u7aef\u7528\u6237\u7ba1\u7406<\/h3>\n<p>\u8fdb\u884c\u5217\u8868\u663e\u793a\u4e0e\u7528\u6237\u72b6\u6001\u4fee\u6539(\u62c9\u9ed1\u64cd\u4f5c)<\/p>\n<p>\u7528\u6237\u5217\u8868\u663e\u793a\u4e3b\u8981\u8fd0\u7528\u4e86\u5206\u9875\u7ba1\u7406\u7ed9\u524d\u7aef\u4f20\u8f93\u6570\u636e(UserVO)\u4ece\u800c\u5728\u9875\u9762\u4e0a\u663e\u793a<\/p>\n<p>\u62c9\u9ed1\u64cd\u4f5c,\u6839\u636e\u524d\u7aef\u4f20\u9001\u8fc7\u6765\u7684\u6570\u636e,\u5728\u6570\u636e\u5e93\u4e2d\u6839\u636e\u7528\u6237id\u641c\u7d22\u6b64\u7528\u6237,\u5931\u8d25\u8fd4\u56de\u5f02\u5e38<\/p>\n<p>\u6210\u529f\u6267\u884cuser.setStatus(userDTO.getStatus());\u00a0\u4f5c\u7528\u662f\u628a\u00a0userDTO\u00a0\u91cc\u7684\u72b6\u6001\u503c\u8d4b\u7ed9\u00a0user\u00a0\u5bf9\u8c61<\/p>\n<p>userCacheManager.updateStatus(user.getUserId(), userDTO.getStatus());\u00a0\u5219\u662f\u8ba9\u7f13\u5b58\u4e2d\u7684\u7528\u6237\u72b6\u6001\u4e0e\u65b0\u72b6\u6001\u4fdd\u6301\u4e00\u81f4,\u6267\u884c updateStatus \u51fd\u6570,\u5148\u5237\u65b0\u7528\u6237\u7f13\u5b58,<\/p>\n<p>&#064;Override<br \/>\n    public List&lt;UserVO&gt; list(UserQueryDTO userQueryDTO) {<br \/>\n        PageHelper.startPage(userQueryDTO.getPageNum(),userQueryDTO.getPageSize());<br \/>\n        return userMapper.selectUserList(userQueryDTO);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public int updateStatus(UserDTO userDTO) {<br \/>\n        User user &#061; userMapper.selectById(userDTO.getUserId());<br \/>\n        if(user&#061;&#061;null){<br \/>\n            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);<br \/>\n        }<br \/>\n        \/\/\u8fd9\u91cc\u662f\u4ece\u524d\u7aef\u62ff\u5230\u7684\u503c,\u5047\u8bbe\u524d\u7aef\u628a\u7528\u6237\u62c9\u9ed1,\u8fd4\u56de\u7684\u5c31\u662f0,\u8bbe\u7f6e\u4e5f\u5c31\u662f0<br \/>\n        user.setStatus(userDTO.getStatus());<br \/>\n        userCacheManager.updateStatus(user.getUserId(),userDTO.getStatus());<br \/>\n        return userMapper.updateById(user);<br \/>\n    } <\/p>\n<p>    public void updateStatus(Long userId,Integer status) {<br \/>\n        \/\/\u5237\u65b0\u7528\u6237\u7f13\u5b58<br \/>\n        String userKey &#061; getUserKey(userId);<br \/>\n        User user &#061; redisService.getCacheObject(userKey, User.class);<br \/>\n        if(user&#061;&#061;null){<br \/>\n            return;<br \/>\n        }<br \/>\n        user.setStatus(status);<br \/>\n        redisService.setCacheObject(userKey, user);<br \/>\n        \/\/\u8bbe\u7f6e\u7528\u6237\u7f13\u5b58\u6709\u6548\u671f\u4e3a10\u5206\u949f<br \/>\n        redisService.expire(userKey, CacheConstants.USER_EXP, TimeUnit.MINUTES);<br \/>\n    } <\/p>\n<p>getCacheObiect\u4e2d\u4eceRedis\u7f13\u5b58\u4e2d\u83b7\u53d6\u5bf9\u8c61\u5e76\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u00a0<\/p>\n<p>\u4eceredis\u7f13\u5b58\u4e2d\u83b7\u53d6\u6307\u5b9akey\u7684\u5bf9\u8c61,\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u7684\u793a\u4f8b<\/p>\n<\/p>\n<p> \/**<br \/>\n     * \u83b7\u5f97\u7f13\u5b58\u7684\u57fa\u672c\u5bf9\u8c61\u3002<br \/>\n     *<br \/>\n     * &#064;param key \u7f13\u5b58\u952e\u503c<br \/>\n     * &#064;return \u7f13\u5b58\u952e\u503c\u5bf9\u5e94\u7684\u6570\u636e<br \/>\n     *\/<br \/>\n    public &lt;T&gt; T getCacheObject(final String key, Class&lt;T&gt; clazz) {<\/p>\n<p> \/\/ \u83b7\u53d6 Redis \u7684 Value \u64cd\u4f5c\u5bf9\u8c61<br \/>\n        ValueOperations&lt;String, T&gt; operation &#061; redisTemplate.opsForValue();<\/p>\n<p>\/\/ \u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u5bf9\u8c61<br \/>\n        T t &#061; operation.get(key); <\/p>\n<p>\/\/ \u5982\u679c\u7f13\u5b58\u503c\u662f String \u7c7b\u578b\u4e14\u76ee\u6807\u7c7b\u578b\u4e5f\u662f String&#xff0c;\u5219\u76f4\u63a5\u8fd4\u56de<br \/>\n        if (t instanceof String) {<br \/>\n            return t;<br \/>\n        }<\/p>\n<p>\/\/ \u5426\u5219\u5c1d\u8bd5\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a JSON \u5b57\u7b26\u4e32\u5e76\u89e3\u6790\u4e3a\u76ee\u6807\u7c7b\u578b<br \/>\n        return JSON.parseObject(String.valueOf(t), clazz);<br \/>\n    } <\/p>\n<h3 id=\"C%E7%AB%AF%E7%94%A8%E6%88%B7%E4%BB%A3%E7%A0%81\">C\u7aef\u7528\u6237\u4ee3\u7801<\/h3>\n<h4 id=\"%E5%8F%91%E9%80%81%E9%AA%8C%E8%AF%81%E7%A0%81%3A\">\u53d1\u9001\u9a8c\u8bc1\u7801:<\/h4>\n<p>\u4ece\u524d\u7aef\u62ff\u5230\u6570\u636e,\u83b7\u53d6\u5230\u7528\u6237\u624b\u673a\u53f7\u7801,<\/p>\n<p>\u8fdb\u5165validatePhone(phone);\u7528\u4e8e\u5224\u65adphone\u662f\u5426\u4e3a\u7a7a(StrUtil.isBlank(phone),isStrUtil.isBlank\u662f<span style=\"color:#fe2c24\">Hutool\u5de5\u5177\u7c7b<\/span>\u4e0b\u7684\u65b9\u6cd5<span style=\"color:#fe2c24\">Hutool\u5de5\u5177\u7c7b<\/span><span style=\"color:null\">\u4e0b\u65b9\u6709\u4ecb\u7ecd<\/span>),\u4e3a\u7a7a\u6267\u884c\u5f02\u5e38,\u4e0d\u4e3a\u7a7a\u5224\u65ad\u624b\u673a\u53f7\u683c\u5f0f\u662f\u5426\u6b63\u786e,\u5982\u679c\u6b63\u786e,\u5219\u6b63\u5e38\u8fdb\u884c\u9891\u7387\u68c0\u67e5<\/p>\n<p>checkDailyRequestLimit()\u68c0\u67e5\u6bcf\u65e5\u8bf7\u6c42\u9650\u5236<\/p>\n<p>\u751f\u6210Redis\u5b58\u50a8\u7684key&#xff08;\u683c\u5f0f\u793a\u4f8b&#xff1a;c:t:13800138000&#xff09;,\u4eceredis\u83b7\u53d6\u5df2\u53d1\u9001\u6b21\u6570(String\u7c7b\u578b),\u8f6c\u5316\u53d1\u9001\u6b21\u6570\u4e3aLong\u7c7b\u578b(\u82e5\u4e3a\u7a7a\u5219\u9ed8\u8ba4\u4e3a0),\u7ed9sendTimes\u8d4b\u503c,\u4e0e\u6bcf\u65e5\u9650\u5236\u6b21\u6570(sendLimit)\u8fdb\u884c\u5bf9\u6bd4,\u7ed3\u679c\u4e3atrue\u5219\u629b\u51fa\u5f02\u5e38<\/p>\n<p>&#064;Override<br \/>\n    public boolean sendCode(UserDTO userDTO) {<br \/>\n        \/\/ 1. \u53c2\u6570\u6821\u9a8c<br \/>\n        String phone &#061; userDTO.getPhone();<br \/>\n        validatePhone(phone);<\/p>\n<p>        \/\/ 2. \u9891\u7387\u63a7\u5236\u68c0\u67e5<br \/>\n        checkRequestFrequency(phone);<\/p>\n<p>        \/\/ 3. \u6bcf\u65e5\u9650\u989d\u68c0\u67e5<br \/>\n        checkDailyRequestLimit(phone);<\/p>\n<p>        \/\/ 4. \u751f\u6210\u5e76\u5b58\u50a8\u9a8c\u8bc1\u7801<br \/>\n        String code &#061; generateVerificationCode(phone);<\/p>\n<p>        \/\/ 5. \u53d1\u9001\u9a8c\u8bc1\u7801<br \/>\n        sendVerificationCode(phone, code);<\/p>\n<p>        System.out.println(&#034;code: &#034;&#043;code);<br \/>\n        return true;<\/p>\n<p>    }<br \/>\n    private void validatePhone(String phone) {<br \/>\n        if (StrUtil.isBlank(phone)) {<br \/>\n            throw new ServiceException(ResultCode.FAILED_USER_PHONE_EMPTY);<br \/>\n        }<\/p>\n<p>        \/\/ \u4e2d\u56fd\u624b\u673a\u53f7\u6b63\u5219&#xff08;11\u4f4d&#xff0c;1\u5f00\u5934&#xff09;<br \/>\n        String regex &#061; &#034;^1[3-9]\\\\\\\\d{9}$&#034;;<br \/>\n        if (!Pattern.matches(regex, phone)) {<br \/>\n            throw new ServiceException(ResultCode.FAILED_USER_PHONE_INVALID);<br \/>\n        }<br \/>\n    }<\/p>\n<p>  private void checkRequestFrequency(String phone) {<br \/>\n        \/\/ getExpire()\u83b7\u53d6\u5f53\u524d Key \u7684\u5269\u4f59\u751f\u5b58\u65f6\u95f4<br \/>\n        String phoneCodeKey &#061; getPhoneCodeKey(phone);<br \/>\n        Long expire &#061; redisService.getExpire(phoneCodeKey, TimeUnit.SECONDS);<br \/>\n        \/\/ \u5982\u679c\u4e0a\u4e00\u6b21\u9a8c\u8bc1\u7801\u7684\u53d1\u9001\u65f6\u95f4\u8ddd\u79bb\u73b0\u5728 \u4e0d\u8db31\u5206\u949f&#xff08;\u5373 \u603b\u6709\u6548\u671f &#8211; \u5269\u4f59\u65f6\u95f4 &lt; 60\u79d2&#xff09;&#xff0c;\u5219\u62d2\u7edd\u65b0\u8bf7\u6c42\u3002<br \/>\n        if (expire !&#061; null &amp;&amp; (emailCodeExpiration * 60 &#8211; expire) &lt; 60) {<br \/>\n            throw new ServiceException(ResultCode.FAILED_FREQUENT);<br \/>\n        }<br \/>\n    }<\/p>\n<p> private void checkDailyRequestLimit(String phone) {<br \/>\n        \/\/ \u6bcf\u5929\u7684\u9a8c\u8bc1\u7801\u83b7\u53d6\u6b21\u6570\u6709\u4e00\u4e2a\u9650\u5236  50 \u6b21 , \u7b2c\u4e8c\u5929  \u8ba1\u6570\u6e050 \u91cd\u65b0\u5f00\u59cb\u8ba1\u6570<br \/>\n        \/\/ \u8ba1\u6570  \u600e\u4e48\u5b58,\u5b58\u5728\u54ea\u91cc ?<br \/>\n        \/\/ \u64cd\u4f5c\u6b21\u6570\u6570\u636e\u9891\u7e41,\u4e0d\u9700\u8981\u5b58\u50a8,  \u8bb0\u5f55\u7684\u6b21\u6570  \u6709\u6548\u65f6\u95f4(\u5f53\u5929\u6709\u6548) redis String  key: c:t:<br \/>\n        \/\/ 1.\u83b7\u53d6\u5df2\u7ecf\u8bf7\u6c42\u7684\u6b21\u6570 \u548c 50 \u8fdb\u884c\u6bd4\u8f83<br \/>\n        String codeTimeKey &#061; getCodeTimeKey(phone);<br \/>\n        String sendTimesStr &#061; redisService.getCacheObject(codeTimeKey, String.class);<br \/>\n        Long sendTimes &#061; sendTimesStr !&#061; null ? Long.parseLong(sendTimesStr) : 0L;<br \/>\n        \/\/ \u5982\u679c\u5927\u4e8e\u9650\u5236,\u629b\u51fa\u5f02\u5e38<br \/>\n        \/\/ \u5982\u679c\u4e0d\u5927\u4e8e\u9650\u5236,\u6b63\u5e38\u6267\u884c\u540e\u7eed\u903b\u8f91,\u5e76\u4e14\u5c06\u83b7\u53d6\u8ba1\u6570&#043;1<br \/>\n        if (sendTimes &gt;&#061; sendLimit) {<br \/>\n            throw new ServiceException(ResultCode.FAILED_TIME_LIMIT);<br \/>\n        }<br \/>\n    } <\/p>\n<hr \/>\n<h4 id=\"%E9%AA%8C%E8%AF%81%E9%AA%8C%E8%AF%81%E7%A0%81\">\u9a8c\u8bc1\u9a8c\u8bc1\u7801<\/h4>\n<p>\u5bf9\u6bd4\u9a8c\u8bc1\u7801\u662f\u5426\u6b63\u786e,\u5982\u679c\u6b63\u786e,\u6839\u636e\u8f93\u5165\u7684phone\u53bb\u6570\u636e\u5e93\u4e2d\u67e5\u8be2<\/p>\n<p>\u5982\u679cuser\u4e3anull\u5219\u5728\u6570\u636e\u5e93\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7528\u6237,\u6dfb\u52a0\u624b\u673a\u53f7,\u7528\u6237\u72b6\u6001<\/p>\n<p>\u6700\u540e\u751f\u6210\u4e13\u5c5e\u4ee4\u724c,\u7528\u4e8e\u540e\u7eed\u9a8c\u8bc1<\/p>\n<p>   &#064;Override<br \/>\n    public String codeLogin(String phone, String code) {<br \/>\n        \/\/\u5224\u65ad\u9a8c\u8bc1\u7801\u662f\u5426\u6b63\u786e<br \/>\n        CheckCode(phone,code);<br \/>\n        User user &#061; userMapper.selectOne(new LambdaQueryWrapper&lt;User&gt;().eq(User::getPhone, phone));<br \/>\n        if(user&#061;&#061;null){   \/\/\u65b0\u7528\u6237<br \/>\n            \/\/\u6ce8\u518c\u903b\u8f91 1.\u5148\u5b8c\u6210\u9a8c\u8bc1\u7801\u7684\u6bd4\u5bf9-&gt;\u6210\u529f,\u5f80\u7cfb\u7edf\u4e2d\u589e\u52a0\u7528\u6237<br \/>\n            user&#061;new User();<br \/>\n            user.setPhone(phone);<br \/>\n            user.setStatus(UserStatus.Normal.getValue());<br \/>\n            userMapper.insert(user);<br \/>\n        }<br \/>\n        return tokenService.createToken(user.getUserId(),secret, UserIdentity.ORDINARY.getValue(),user.getNickName(),user.getHeadImage());<\/p>\n<p>private void CheckCode(String phone, String code) {<br \/>\n        String phoneCodeKey &#061; getPhoneCodeKey(phone);<br \/>\n        String cacheCode &#061; redisService.getCacheObject(phoneCodeKey,String.class);<\/p>\n<p>        if(StrUtil.isEmpty(cacheCode)){<br \/>\n            throw new ServiceException(ResultCode.FAILED_INVALID_CODE);<br \/>\n        }<br \/>\n        if(!cacheCode.equals(code)){<br \/>\n            throw new ServiceException(ResultCode.FAILED_CODE_MISMATCH);<br \/>\n        }<br \/>\n        redisService.deleteObject(phoneCodeKey);<br \/>\n    } <\/p>\n<h4 id=\"%E9%80%80%E5%87%BA%E7%99%BB%E5%BD%95\">\u9000\u51fa\u767b\u5f55<\/h4>\n<p>\u6700\u5f00\u59cb\u68c0\u6d4btoken\u662f\u5426\u4e3a\u7a7a\u8fd9\u6b65\u662f\u4e00\u4e2a\u4fdd\u969c,\u9632\u6b62\u6ca1\u6709\u751f\u6210\u4ee4\u724c<\/p>\n<p>public static final String PREFIX &#061; &#034;Bearer &#034;;\u4e3a\u4ee4\u724c\u524d\u7f00,\u5982\u679c\u5b58\u5728\u4ee4\u724c\u524d\u7f00\u5219\u628a\u524d\u7f00\u66ff\u6362\u6210\u7a7a<\/p>\n<p>\u6700\u540e\u5220\u9664\u4ee4\u724c<\/p>\n<p> &#064;Override<br \/>\n    public boolean logout(String token) {<br \/>\n        \/\/\u68c0\u67e5token\u662f\u5426\u4e3a\u7a7a<br \/>\n        if (StrUtil.isEmpty(token)) {<br \/>\n            throw new ServiceException(ResultCode.TOKEN_IS_DEFAULT);<br \/>\n        }<br \/>\n        \/\/\u518d\u5904\u7406\u524d\u7f00<br \/>\n        if (token.startsWith(HttpConstants.PREFIX)) {<br \/>\n            token &#061; token.replaceFirst(HttpConstants.PREFIX,StrUtil.EMPTY);<br \/>\n        }<\/p>\n<p>        return tokenService.deleteLoginUser(token,secret);<\/p>\n<p>    }<\/p>\n<h4 id=\"%E7%99%BB%E5%BD%95%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%E5%8A%9F%E8%83%BD\">\u767b\u5f55\u7528\u6237\u4fe1\u606f\u529f\u80fd<\/h4>\n<p>LoginUserVO,\u8fd4\u56de\u7ed9\u524d\u7aef\u7684\u6570\u636e(\u5305\u62ec\u5934\u50cf\u548c\u6635\u79f0)<\/p>\n<p>\u6839\u636etoken\u83b7\u53d6\u767b\u5f55\u7528\u6237\u4fe1\u606f\u8fd4\u56de,\u5305\u542b\u7528\u6237\u57fa\u672c\u4fe1\u606f\u7684VO\u5bf9\u8c61<\/p>\n<p>\u7528\u6237\u5934\u50cf\u5b57\u6bb5\u9700\u8981\u62fc\u63a5\u4e0b\u8f7d\u5730\u5740\u524d\u7f00,\u4f7f\u7528StrUtil.isNotEmpty\u786e\u4fdd\u5934\u50cf\u5b57\u6bb5\u975e\u7a7a<\/p>\n<p>    &#064;Override<br \/>\n    public R&lt;LoginUserVO&gt; info(String token) {<\/p>\n<p>\/\/        if (StrUtil.isNotEmpty(token) &amp;&amp; token.startsWith(HttpConstants.PREFIX)) {<br \/>\n\/\/            token &#061; token.replaceFirst(HttpConstants.PREFIX, StrUtil.EMPTY);<br \/>\n\/\/        }<\/p>\n<p>        \/\/ \u5148\u68c0\u67e5token\u662f\u5426\u4e3a\u7a7a<br \/>\n        if (StrUtil.isEmpty(token)) {<br \/>\n            throw new ServiceException(ResultCode.TOKEN_IS_DEFAULT);<br \/>\n        }<br \/>\n\/\/      \u518d\u5904\u7406\u524d\u7f00<br \/>\n        if (token.startsWith(HttpConstants.PREFIX)) {<br \/>\n            token &#061; token.substring(HttpConstants.PREFIX.length());<br \/>\n        }<\/p>\n<p>        LoginUser loginUser &#061; tokenService.getLoginUser(token, secret);<\/p>\n<p>        if(loginUser&#061;&#061;null){<br \/>\n            return R.fail();<br \/>\n        }<br \/>\n        LoginUserVO loginUserVO&#061;new LoginUserVO();<br \/>\n        loginUserVO.setNickName(loginUser.getNickName());<br \/>\n        if(StrUtil.isNotEmpty(loginUser.getHeadImage())){<br \/>\n            loginUserVO.setHeadImage(download&#043;loginUser.getHeadImage());<br \/>\n        }<br \/>\n        return R.ok(loginUserVO);<br \/>\n    }<\/p>\n<h4 id=\"%C2%A0%E7%94%A8%E6%88%B7%E8%AF%A6%E6%83%85%E4%B8%8E%E7%94%A8%E6%88%B7%E7%BC%96%E8%BE%91\">\u00a0\u7528\u6237\u8be6\u60c5\u4e0e\u7528\u6237\u7f16\u8f91<\/h4>\n<p>\u7528\u6237\u8be6\u60c5<\/p>\n<p>\u4ece\u7ebf\u7a0b\u6c60\u4e2d\u83b7\u53d6userId\u7684\u503c<\/p>\n<p>\u5b9a\u4e49\u4e00\u4e2auserVO\u5bf9\u8c61,\u4ece\u6570\u636e\u5e93\u4e2d\u6839\u636euserId\u67e5\u8be2\u5185\u5bb9\u8d4b\u503c\u7ed9userVO<\/p>\n<p>\u5982\u679c\u7528\u6237\u5b58\u5728,\u8bbe\u7f6e\u5934\u50cf,\u5b58\u5165userVO,\u6700\u540e\u8fd4\u56de\u7ed9\u524d\u7aef<\/p>\n<p>\u7528\u6237\u7f16\u8f91<\/p>\n<p>\u5148\u628a\u7528\u6237\u83b7\u53d6\u51fa\u6765,\u6839\u636e\u524d\u7aef\u8f93\u5165\u7684\u5185\u5bb9\u53bb\u8ddf\u65b0\u6570\u636e\u5e93\u4e2d\u7684\u503c<\/p>\n<p>\u6700\u540e\u66f4\u65b0\u7f13\u5b58<\/p>\n<p>extracted(),\u5237\u65b0\u7528\u6237\u7f13\u5b58\u548c\u767b\u5f55\u72b6\u6001\u4fe1\u606f<\/p>\n<p>UserCacheManager .refreshUser:\u00a0\u7528\u6237\u7f13\u5b58\u5237\u65b0\u63a5\u53e3<\/p>\n<p>TokenService.refreshLoginUser:\u00a0Token\u4fe1\u606f\u5237\u65b0\u63a5\u53e3<\/p>\n<p> &#064;Override<br \/>\n    public UserVO detail() {<br \/>\n        Long userId&#061; ThreadLocalUtil.get(Constants.USER_ID,Long.class);<br \/>\n        if(userId&#061;&#061;null){<br \/>\n            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);<br \/>\n        }<br \/>\n        UserVO userVO;<br \/>\n        userVO&#061;userCacheManager.getUserById(userId);<br \/>\n        if(userVO&#061;&#061;null){<br \/>\n            throw new ServiceException(ResultCode.FAILED_USER_NOT_EXISTS);<br \/>\n        }<br \/>\n        if(StrUtil.isNotEmpty(userVO.getHeadImage())){<br \/>\n            userVO.setHeadImage(download&#043;userVO.getHeadImage());<br \/>\n        }<br \/>\n        return userVO;<br \/>\n    }<br \/>\n &#064;Override<br \/>\n    public int edit(UserUpdateDTO userUpdateDTO) {<br \/>\n        User user &#061; getUser();<br \/>\n        user.setNickName(userUpdateDTO.getNickName());<br \/>\n        user.setSex(userUpdateDTO.getSex());<br \/>\n        user.setSchoolName(userUpdateDTO.getSchoolName());<br \/>\n        user.setMajorName(userUpdateDTO.getMajorName());<br \/>\n        user.setPhone(userUpdateDTO.getPhone());<br \/>\n        user.setEmail(userUpdateDTO.getEmail());<br \/>\n        user.setWechat(userUpdateDTO.getWechat());<br \/>\n        user.setIntroduce(userUpdateDTO.getIntroduce());<br \/>\n        \/\/\u66f4\u65b0\u7528\u6237\u7f13\u5b58<br \/>\n        extracted(user);<br \/>\n        return userMapper.updateById(user);<br \/>\n    }<\/p>\n<p>    private void extracted(User user) {<br \/>\n        userCacheManager.refreshUser(user);<br \/>\n        tokenService.refreshLoginUser(user.getNickName(), user.getHeadImage(),<br \/>\n                ThreadLocalUtil.get(Constants.USER_KEY, String.class));<br \/>\n    }<\/p>\n<h3 id=\"%C2%A0%E7%94%A8%E6%88%B7%E7%AB%9E%E8%B5%9B%E6%8E%A5%E5%8F%A3\">\u00a0\u7528\u6237\u7ade\u8d5b\u63a5\u53e3<\/h3>\n<h4 id=\"%E7%94%A8%E6%88%B7%E6%8A%A5%E5%90%8D%E7%AB%9E%E8%B5%9B\">\u7528\u6237\u62a5\u540d\u7ade\u8d5b<\/h4>\n<p>\u83b7\u53d6\u5f53\u524d\u7528\u6237\u4fe1\u606f,\u7b5b\u9009\u7528\u6237\u662f\u5426\u7b26\u5408\u6761\u4ef6(<span style=\"color:#fe2c24\">1.\u7528\u6237\u5904\u4e8e\u767b\u5f55\u72b6\u6001 2.\u4e0d\u80fd\u62a5\u540d\u4e0d\u5b58\u5728\u7684\u7ade\u8d5b 3.\u4e0d\u80fd\u91cd\u590d\u62a5\u540d 4.\u5df2\u7ecf\u5f00\u8d5b\u7684\u7981\u6b62\u62a5\u540d<\/span>)<\/p>\n<p>\u6761\u4ef6\u7b26\u5408\u4e4b\u540e,\u5f80\u7528\u6237\u7ade\u8d5b\u8868\u4e2d\u6dfb\u52a0\u6570\u636e(\u5e95\u5c42\u4f7f\u7528list\u7ed3\u6784\u5b58\u50a8\u6570\u636e(\u5934\u63d2\u6cd5))<\/p>\n<p>  &#064;Override<br \/>\n    public int enter(String token, Long examId) {<\/p>\n<p>\/\/        \u83b7\u53d6\u5f53\u524d\u7528\u6237\u7684\u4fe1\u606f  status<br \/>\n        Long userId &#061; ThreadLocalUtil.get(Constants.USER_ID, Long.class);<br \/>\n\/\/        UserVO user &#061; userCacheManager.getUserById(userId);<br \/>\n\/\/        if (user.getStatus()&#061;&#061;0){<br \/>\n\/\/            throw new ServiceException(ResultCode.FAILED_USER_BANNED);<br \/>\n\/\/        }<\/p>\n<p>        \/\/\u4f7f\u7528spring aop<\/p>\n<p>\/\/\u62a5\u540d\u662f\u5426\u7b26\u5408\u6761\u4ef6 (1.\u7528\u6237\u5904\u4e8e\u767b\u5f55\u72b6\u6001 2.\u4e0d\u80fd\u62a5\u540d\u4e0d\u5b58\u5728\u7684\u7ade\u8d5b 3.\u4e0d\u80fd\u91cd\u590d\u62a5\u540d 4.\u5df2\u7ecf\u5f00\u8d5b\u7684\u7981\u6b62\u62a5\u540d)<br \/>\n        Exam exam &#061; examMapper.selectById(examId);<br \/>\n        if(exam&#061;&#061;null){<br \/>\n            throw new ServiceException(ResultCode.EXAM_RESULT_NOT_EXIST);<br \/>\n        }<br \/>\n        if(exam.getStartTime().isBefore(LocalDateTime.now())){<br \/>\n            throw new ServiceException(ResultCode.EXAM_IS_START);<br \/>\n        }<br \/>\n\/\/        Long userId&#061; tokenService.getUserId(token,secret);<br \/>\n\/\/        Long userId &#061; userId;<br \/>\n        UserExam userExam &#061; userExamMapper.selectOne(new LambdaQueryWrapper&lt;UserExam&gt;()<br \/>\n                .eq(UserExam::getExamId, examId)<br \/>\n                .eq(UserExam::getUserId, userId));<br \/>\n        if(userExam!&#061;null){<br \/>\n            throw new ServiceException(ResultCode.USER_EXAM_HAS_ENTER);<br \/>\n        }<br \/>\n        examCacheManager.addUserExamCache(userId, examId);<br \/>\n        userExam&#061;new UserExam();<br \/>\n        userExam.setExamId(examId);<br \/>\n        userExam.setUserId(userId);<br \/>\n        return userExamMapper.insert(userExam);<br \/>\n    }<\/p>\n<h4 id=\"%E7%94%A8%E6%88%B7%E7%AB%9E%E8%B5%9B%E6%8A%A5%E5%90%8D%E6%8E%A5%E5%8F%A3%E6%9F%A5%E8%AF%A2\">\u7528\u6237\u7ade\u8d5b\u62a5\u540d\u63a5\u53e3\u67e5\u8be2<\/h4>\n<p>type :0:\u4ee3\u8868\u672a\u5b8c\u8d5b 1:\u4ee3\u8868\u5386\u53f2\u7ade\u8d5b\u00a0<\/p>\n<p>\u5148\u67e5\u8be2\u7528\u6237\u4fe1\u606f,\u628atype\u7684\u503c\u8bbe\u7f6e\u4e3a2,<\/p>\n<p>userExamMapper.selectUserExamList(userId)\u6839\u636euserId\u83b7\u53d6\u6307\u5b9a\u7c7b\u578b\u7684\u8003\u8bd5\u5217\u8868\u957f\u5ea6<\/p>\n<p>\u5224\u65adtype\u548cuserId\u662f\u5426\u4e3a\u7a7a<\/p>\n<p>\u4e0d\u4e3a\u7a7a\u751f\u6210redis\u552f\u4e00\u6807\u8bc6\u7b26,\u8fd4\u56de\u4e00\u4e2ajson\u5f62\u5f0f\u7684\u6570\u636e<\/p>\n<p>  &#064;Override<br \/>\n    public TableDataInfo list(ExamQueryDTO examQueryDTO) {<br \/>\n        Long userId &#061; ThreadLocalUtil.get(Constants.USER_ID, Long.class);<br \/>\n        examQueryDTO.setType(ExamListType.USER_EXAM_LIST.getValue());<br \/>\n        Long total &#061; examCacheManager.getListSize(ExamListType.USER_EXAM_LIST.getValue(),userId);<br \/>\n        List&lt;ExamVO&gt; examVOList;<br \/>\n        if(total &#061;&#061; null || total &lt;&#061; 0){\/\/\u7f13\u5b58\u4e0d\u5b58\u5728\u65f6\u7684\u5904\u7406&#xff1a;<br \/>\n            \/\/\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u6211\u7684\u7ade\u8d5b\u5217\u8868<br \/>\n            PageHelper.startPage(examQueryDTO.getPageNum(),examQueryDTO.getPageSize());<br \/>\n            examVOList &#061; userExamMapper.selectUserExamList(userId);<br \/>\n            \/\/\u5c06\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u540c\u6b65\u7ed9\u7f13\u5b58<br \/>\n            examCacheManager.refreshCache(examQueryDTO.getType(),userId);<br \/>\n            \/\/\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2<br \/>\n            total&#061;new PageInfo&lt;&gt;(examVOList).getTotal();<br \/>\n        }else{\/\/\u7f13\u5b58\u5b58\u5728\u65f6\u7684\u5904\u7406&#xff1a;<br \/>\n            examVOList &#061; examCacheManager.getExamVOList(examQueryDTO,userId);<br \/>\n            \/\/\u4eceredis\u4e2d\u67e5\u8be2,\u5728\u67e5\u8be2\u65f6,\u51fa\u73b0\u5f02\u5e38\u60c5\u51b5,\u53ef\u80fd\u4f1a\u91cd\u65b0\u5237\u65b0\u6570\u636e,\u8fd9\u6b21\u67e5\u8be2\u7528\u6237\u6570\u636e\u7684\u66f4\u65b0<br \/>\n\/\/            0:\u4ee3\u8868\u672a\u5b8c\u8d5b 1:\u8868\u793a\u5f00\u59cb\u7ade\u8d5b<br \/>\n            total &#061; examCacheManager.getListSize(examQueryDTO.getType(),userId);<br \/>\n        }<br \/>\n\/\/        \u7a7a\u7ed3\u679c\u5904\u7406&#xff1a;<br \/>\n        if  (CollectionUtil.isEmpty(examVOList)){<br \/>\n            return TableDataInfo.empty();<br \/>\n        }<br \/>\n        \/\/\u83b7\u53d6\u7b26\u5408\u67e5\u8be2\u6761\u4ef6\u7684\u6570\u636e\u603b\u6570<br \/>\n        \/\/\u4ece\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u6570\u636e,\u4e0d\u662f\u4eceredis\u4e2d\u67e5\u8be2\u6570\u636e<br \/>\n        return TableDataInfo.success(examVOList,total);<\/p>\n<p>    }<\/p>\n<p>public Long getListSize(Integer examListType, Long userId) {<br \/>\n    \/\/ 1. \u53c2\u6570\u6821\u9a8c&#xff08;\u793a\u4f8b&#xff0c;\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8c03\u6574&#xff09;<br \/>\n    if (examListType &#061;&#061; null || userId &#061;&#061; null) {<br \/>\n        throw new IllegalArgumentException(&#034;\u53c2\u6570\u4e0d\u80fd\u4e3anull&#034;);<br \/>\n    }<\/p>\n<p>    \/\/ 2. \u751f\u6210\u4e1a\u52a1\u552f\u4e00\u7684Redis\u952e<br \/>\n    String examListKey &#061; getExamListKey(examListType, userId);<\/p>\n<p>    \/\/ 3. \u83b7\u53d6Redis\u5217\u8868\u957f\u5ea6&#xff08;\u8fd4\u56deLong\u7c7b\u578b&#xff0c;\u53ef\u80fd\u4e3a0&#xff09;<br \/>\n    return redisService.getListSize(examListKey);<br \/>\n}<br \/>\n \/\/\u672a\u67e5\u51fa\u4efb\u4f55\u6570\u636e\u65f6\u8c03\u7528<br \/>\n    public static TableDataInfo empty() {<br \/>\n        TableDataInfo rspData &#061; new TableDataInfo();<br \/>\n        rspData.setCode(ResultCode.SUCCESS.getCode());<br \/>\n        rspData.setRows(new ArrayList&lt;&gt;());<br \/>\n        rspData.setMsg(ResultCode.SUCCESS.getMsg());<br \/>\n        rspData.setTotal(0);<br \/>\n        return rspData;<br \/>\n    }<\/p>\n<p>    \/\/\u67e5\u51fa\u6570\u636e\u65f6\u8c03\u7528<br \/>\n    public static TableDataInfo success(List&lt;?&gt; list,long total) {<br \/>\n        TableDataInfo rspData &#061; new TableDataInfo();<br \/>\n        rspData.setCode(ResultCode.SUCCESS.getCode());<br \/>\n        rspData.setRows(list);<br \/>\n        rspData.setMsg(ResultCode.SUCCESS.getMsg());<br \/>\n        rspData.setTotal(total);<br \/>\n        return rspData;<br \/>\n    } <\/p>\n<h3 id=\"%C2%A0%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF%E5%88%97%E8%A1%A8\">\u00a0\u7528\u6237\u4fe1\u606f\u5217\u8868<\/h3>\n<p>\u83b7\u53d6\u7528\u6237\u6d88\u606f\u5217\u8868&#xff08;\u5e26\u5206\u9875&#xff0c;\u4f18\u5148\u4ece\u7f13\u5b58\u8bfb\u53d6&#xff09;<\/p>\n<p>\u4eceThreadLocal\u83b7\u53d6\u5f53\u524d\u7528\u6237ID \u68c0\u67e5\u7f13\u5b58\u4e2d\u662f\u5426\u5b58\u5728\u6d88\u606f\u5217\u8868<\/p>\n<p>\u7f13\u5b58\u4e0d\u5b58\u5728,\u4e3a\u7a7a\u65f6\u67e5\u8be2\u6570\u636e\u5e93\u5e76\u5237\u65b0\u7f13\u5b58<\/p>\n<p>\u8fd4\u56de\u5206\u9875\u683c\u5f0f\u7684\u7edf\u4e00\u54cd\u5e94<\/p>\n<p>public TableDataInfo list(PageQueryDTO dto) {<br \/>\n    \/\/ 1. \u83b7\u53d6\u5f53\u524d\u7528\u6237ID&#xff08;\u4ece\u7ebf\u7a0b\u4e0a\u4e0b\u6587&#xff09;<br \/>\n    Long userId &#061; ThreadLocalUtil.get(Constants.USER_ID, Long.class);<br \/>\n    if (userId &#061;&#061; null) {<br \/>\n        throw new ServiceException(&#034;\u7528\u6237\u672a\u767b\u5f55&#034;);<br \/>\n    }<\/p>\n<p>    \/\/ 2. \u68c0\u67e5\u7f13\u5b58\u662f\u5426\u5b58\u5728\u6709\u6548\u6570\u636e<br \/>\n    Long total &#061; messageCacheManager.getListSize(userId);<br \/>\n    List&lt;MessageTextVO&gt; messageTextVOList;<\/p>\n<p>    \/\/ 3. \u7f13\u5b58\u4e0d\u5b58\u5728\u65f6\u8d70\u6570\u636e\u5e93\u67e5\u8be2<br \/>\n    if (total &#061;&#061; null || total &lt;&#061; 0) {<br \/>\n        \/\/ 3.1 \u542f\u7528\u5206\u9875\u67e5\u8be2<br \/>\n        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());<br \/>\n        messageTextVOList &#061; messageTextMapper.selectUserMsgList(userId);<\/p>\n<p>        \/\/ 3.2 \u5237\u65b0\u7f13\u5b58<br \/>\n        messageCacheManager.refreshCache(userId);<br \/>\n        total &#061; new PageInfo&lt;&gt;(messageTextVOList).getTotal();<br \/>\n    }<br \/>\n    \/\/ 4. \u7f13\u5b58\u5b58\u5728\u65f6\u76f4\u63a5\u8bfb\u53d6<br \/>\n    else {<br \/>\n        messageTextVOList &#061; messageCacheManager.getMsgTextVOList(dto, userId);<br \/>\n    }<\/p>\n<p>    \/\/ 5. \u5904\u7406\u7a7a\u7ed3\u679c<br \/>\n    if (CollectionUtil.isEmpty(messageTextVOList)) {<br \/>\n        return TableDataInfo.empty();<br \/>\n    }<\/p>\n<p>    \/\/ 6. \u8fd4\u56de\u7edf\u4e00\u5206\u9875\u54cd\u5e94<br \/>\n    return TableDataInfo.success(messageTextVOList, total);<br \/>\n} <\/p>\n<hr \/>\n<h4 id=\"ThreadLocalUtil\">ThreadLocalUtil<\/h4>\n<p><span style=\"color:#fe2c24\">ThreadLocalUtil\u662f\u4e00\u4e2a\u5de5\u5177\u7c7b&#xff0c;\u5c01\u88c5\u4e86Java\u7684ThreadLocal\u64cd\u4f5c&#xff0c;ThreadLocal\u5de5\u5177\u7c7b&#xff08;\u57fa\u4e8eTransmittableThreadLocal\u5b9e\u73b0&#xff09;<\/span><\/p>\n<p>\u5c01\u88c5\u7ebf\u7a0b\u9694\u79bb\u7684\u53d8\u91cf\u5b58\u50a8\u529f\u80fd&#xff0c;\u89e3\u51b3\u539f\u751fThreadLocal\u5728\u7ebf\u7a0b\u6c60\u573a\u666f\u4e0b\u7684\u6570\u636e\u6c61\u67d3\u95ee\u9898<\/p>\n<p>\u4f7f\u7528TransmittableThreadLocal\u66ff\u4ee3\u539f\u751fThreadLocal&#xff0c;\u652f\u6301\u7ebf\u7a0b\u6c60\u73af\u5883<\/p>\n<p>\u6bcf\u4e2a\u7ebf\u7a0b\u72ec\u7acb\u7ef4\u62a4ConcurrentHashMap\u5b58\u50a8\u6570\u636e&#xff0c;\u7ebf\u7a0b\u5b89\u5168<\/p>\n<p>\u81ea\u52a8\u5904\u7406null\u503c\u5b58\u50a8&#xff08;\u8f6c\u4e3a\u7a7a\u5b57\u7b26\u4e32)<\/p>\n<p>\u5fc5\u987b\u663e\u5f0f\u8c03\u7528remove()\u907f\u514d\u5185\u5b58\u6cc4\u6f0f<span style=\"color:#fe2c24\">\u8be6\u60c5\u770b\u6ce8\u91ca<\/span><\/p>\n<p>\/\/ThreadLocalUtil\u662f\u4e00\u4e2a\u5de5\u5177\u7c7b&#xff0c;\u5c01\u88c5\u4e86Java\u7684ThreadLocal\u64cd\u4f5c&#xff0c;<br \/>\n\/\/\u7528\u4e8e\u5b9e\u73b0\u7ebf\u7a0b\u9694\u79bb\u7684\u53d8\u91cf\u5b58\u50a8&#xff08;\u6bcf\u4e2a\u7ebf\u7a0b\u72ec\u7acb\u5b58\u53d6\u6570\u636e&#xff0c;\u4e92\u4e0d\u5e72\u6270&#xff09;\u3002<br \/>\npublic class ThreadLocalUtil {<br \/>\n\/\/    \u4f7f\u7528 TransmittableThreadLocal&#xff08;\u800c\u975e\u539f\u751f ThreadLocal&#xff09;&#xff0c;<br \/>\n\/\/    \u89e3\u51b3\u539f\u751f ThreadLocal \u5728\u7ebf\u7a0b\u6c60\u4e2d\u7ebf\u7a0b\u590d\u7528\u5bfc\u81f4\u7684\u6570\u636e\u9519\u4e71\u95ee\u9898\u3002<br \/>\n    private static final TransmittableThreadLocal&lt;Map&lt;String, Object&gt;&gt;<br \/>\n            THREAD_LOCAL &#061; new TransmittableThreadLocal&lt;&gt;();<\/p>\n<p>    \/**<br \/>\n     * \u5b58\u50a8\u952e\u503c\u5bf9\u5230\u5f53\u524d\u7ebf\u7a0b\u4e0a\u4e0b\u6587<br \/>\n     * &#064;param key \u952e&#xff08;\u975e\u7a7a&#xff09;<br \/>\n     * &#064;param value \u503c&#xff08;\u81ea\u52a8\u8f6c\u6362null\u4e3a\u7a7a\u5b57\u7b26\u4e32&#xff09;<br \/>\n     *\/<\/p>\n<p>    public static void set(String key, Object value) {<br \/>\n        Map&lt;String, Object&gt; map &#061; getLocalMap();<br \/>\n        map.put(key, value &#061;&#061; null ? StrUtil.EMPTY : value);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u4ece\u5f53\u524d\u7ebf\u7a0b\u4e0a\u4e0b\u6587\u83b7\u53d6\u503c&#xff08;\u5e26\u7c7b\u578b\u8f6c\u6362&#xff09;<br \/>\n     * &#064;param key \u952e<br \/>\n     * &#064;param clazz \u76ee\u6807\u7c7b\u578bClass\u5bf9\u8c61<br \/>\n     * &#064;return \u503c&#xff08;\u4e0d\u5b58\u5728\u65f6\u8fd4\u56denull&#xff09;<br \/>\n     * &#064;param &lt;T&gt; \u8fd4\u56de\u503c\u6cdb\u578b<br \/>\n     *\/<br \/>\n    public static &lt;T&gt; T get(String key, Class&lt;T&gt; clazz) {<br \/>\n        Map&lt;String, Object&gt; map &#061; getLocalMap();<br \/>\n        return (T) map.getOrDefault(key, null);<br \/>\n    }<\/p>\n<p>    \/**<br \/>\n     * \u83b7\u53d6\u5f53\u524d\u7ebf\u7a0b\u7684\u5b58\u50a8Map&#xff08;\u4e0d\u5b58\u5728\u65f6\u81ea\u52a8\u521d\u59cb\u5316&#xff09;<br \/>\n     *<br \/>\n     * \u6ce8\u610f&#xff1a;\u4f7f\u7528ConcurrentHashMap\u4fdd\u8bc1\u7ebf\u7a0b\u5b89\u5168&lt;\/p&gt;<br \/>\n     *<br \/>\n     * &#064;return \u5f53\u524d\u7ebf\u7a0b\u5173\u8054\u7684Map&#xff08;\u6c38\u4e0d\u4e3anull&#xff09;<br \/>\n     *\/<\/p>\n<p>\/\/    \u6bcf\u4e2a\u7ebf\u7a0b\u72ec\u7acb\u7ef4\u62a4\u4e00\u4e2a Map&lt;String, Object&gt;&#xff0c;<br \/>\n\/\/    \u901a\u8fc7\u952e\u503c\u5bf9&#xff08;Key-Value&#xff09;\u5b58\u50a8\u6570\u636e&#xff0c;\u7ebf\u7a0b\u95f4\u6570\u636e\u4e92\u4e0d\u5e72\u6270\u3002<br \/>\n    public static Map&lt;String, Object&gt; getLocalMap() {<br \/>\n        Map&lt;String, Object&gt; map &#061; THREAD_LOCAL.get();<br \/>\n        if (map &#061;&#061; null) {<br \/>\n            map &#061; new ConcurrentHashMap&lt;String, Object&gt;();<br \/>\n            THREAD_LOCAL.set(map);<br \/>\n        }<br \/>\n        return map;<br \/>\n    }<\/p>\n<p>     \/**<br \/>\n     * \u6e05\u9664\u5f53\u524d\u7ebf\u7a0b\u7684\u5b58\u50a8Map&#xff08;<br \/>\n     *<br \/>\n     *   \u4f7f\u7528\u573a\u666f&#xff1a;<br \/>\n     *   \u7ebf\u7a0b\u6c60\u573a\u666f\u5fc5\u987b\u8c03\u7528&#xff0c;\u907f\u514d\u5185\u5b58\u6cc4\u6f0f<br \/>\n     *   \u8bf7\u6c42\u5904\u7406\u7ed3\u675f\u65f6\u5efa\u8bae\u8c03\u7528<br \/>\n     *\/<\/p>\n<p>    \/\/\u6e05\u9664\u5f53\u524d\u7ebf\u7a0b\u7684 Map&#xff0c;\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f&#xff08;\u5c24\u5176\u5728\u7ebf\u7a0b\u6c60\u573a\u666f\u4e2d\u5fc5\u987b\u8c03\u7528&#xff09;<br \/>\n    public static void remove() {<br \/>\n        THREAD_LOCAL.remove();<br \/>\n    }<br \/>\n}<\/p>\n<p>\u00a0<\/p>\n<h3 id=\"Hutool%E5%B7%A5%E5%85%B7%E5%BA%93\">Hutool\u5de5\u5177\u5e93<\/h3>\n<p><span style=\"color:#fe2c24\">\u5b98\u65b9\u7f51\u7ad9:<\/span><\/p>\n<p>Hutool&#x1f36c;\u4e00\u4e2a\u529f\u80fd\u4e30\u5bcc\u4e14\u6613\u7528\u7684Java\u5de5\u5177\u5e93&#xff0c;\u6db5\u76d6\u4e86\u5b57\u7b26\u4e32\u3001\u6570\u5b57\u3001\u96c6\u5408\u3001\u7f16\u7801\u3001\u65e5\u671f\u3001\u6587\u4ef6\u3001IO\u3001\u52a0\u5bc6\u3001\u6570\u636e\u5e93JDBC\u3001JSON\u3001HTTP\u5ba2\u6237\u7aef\u7b49\u529f\u80fd\u3002<\/p>\n<p>\u5bfc\u5165\u4f9d\u8d56<\/p>\n<p>&lt;dependency&gt;<br \/>\n    &lt;groupId&gt;cn.hutool&lt;\/groupId&gt;<br \/>\n    &lt;artifactId&gt;hutool-core&lt;\/artifactId&gt;<br \/>\n    &lt;version&gt;5.8.16&lt;\/version&gt; &lt;!&#8211; \u4ee5\u6700\u65b0\u7248\u672c\u4e3a\u51c6 &#8211;&gt;<br \/>\n&lt;\/dependency&gt;<\/p>\n<h4 id=\"%E5%B8%B8%E7%94%A8%E5%8A%9F%E8%83%BD%E4%BB%8B%E7%BB%8D%C2%A0\"><span style=\"color:#fe2c24\">\u5e38\u7528\u529f\u80fd\u4ecb\u7ecd<\/span>\u00a0<\/h4>\n<p>1.1 \u5b57\u7b26\u4e32\u5de5\u5177&#xff08;StrUtil&#xff09;<\/p>\n<p>import cn.hutool.core.util.StrUtil;<\/p>\n<p>\/\/ \u5224\u7a7a<br \/>\nboolean isBlank &#061; StrUtil.isBlank(&#034;  &#034;); \/\/ true&#xff08;\u7a7a\u6216\u7a7a\u767d\u5b57\u7b26&#xff09;<br \/>\nboolean isEmpty &#061; StrUtil.isEmpty(&#034;&#034;);   \/\/ true&#xff08;\u4ec5\u7a7a\u5b57\u7b26\u4e32&#xff09;<\/p>\n<p>\/\/ \u683c\u5f0f\u5316\u5b57\u7b26\u4e32<br \/>\nString formatted &#061; StrUtil.format(&#034;Hello, {}!&#034;, &#034;Hutool&#034;); \/\/ &#034;Hello, Hutool!&#034;<\/p>\n<p>\/\/ \u5b57\u7b26\u4e32\u622a\u53d6\u3001\u586b\u5145\u3001\u53cd\u8f6c<br \/>\nString sub &#061; StrUtil.sub(&#034;HelloWorld&#034;, 2, 5); \/\/ &#034;llo&#034;<br \/>\nString padded &#061; StrUtil.padPre(&#034;123&#034;, 5, &#039;0&#039;); \/\/ &#034;00123&#034;<br \/>\nString reversed &#061; StrUtil.reverse(&#034;ABC&#034;); \/\/ &#034;CBA&#034; <\/p>\n<p>1.2 \u6570\u5b57\u5de5\u5177&#xff08;NumberUtil&#xff09;<\/p>\n<p>import cn.hutool.core.util.NumberUtil;<\/p>\n<p>\/\/ \u6570\u5b66\u8ba1\u7b97<br \/>\nint sum &#061; NumberUtil.add(1, 2, 3); \/\/ 6<br \/>\ndouble div &#061; NumberUtil.div(10, 3, 2); \/\/ 3.33&#xff08;\u4fdd\u75592\u4f4d\u5c0f\u6570&#xff09;<\/p>\n<p>\/\/ \u6570\u5b57\u5224\u65ad<br \/>\nboolean isNumber &#061; NumberUtil.isNumber(&#034;123.45&#034;); \/\/ true<br \/>\nboolean isInteger &#061; NumberUtil.isInteger(&#034;100&#034;); \/\/ true <\/p>\n<p>1.3 \u65e5\u671f\u65f6\u95f4\u5de5\u5177&#xff08;DateUtil&#xff09;<\/p>\n<p>import cn.hutool.core.date.DateUtil;<\/p>\n<p>\/\/ \u65e5\u671f\u89e3\u6790\u4e0e\u683c\u5f0f\u5316<br \/>\nDate date &#061; DateUtil.parse(&#034;2023-10-01&#034;); \/\/ String \u2192 Date<br \/>\nString dateStr &#061; DateUtil.format(date, &#034;yyyy\/MM\/dd&#034;); \/\/ &#034;2023\/10\/01&#034;<\/p>\n<p>\/\/ \u65e5\u671f\u8ba1\u7b97<br \/>\nDate tomorrow &#061; DateUtil.offsetDay(new Date(), 1); \/\/ \u660e\u5929<br \/>\nlong betweenDays &#061; DateUtil.between(date, new Date(), DateUnit.DAY); \/\/ \u76f8\u5dee\u5929\u6570<\/p>\n<p>\/\/ \u83b7\u53d6\u65f6\u95f4\u90e8\u5206<br \/>\nint year &#061; DateUtil.year(date); \/\/ 2023<br \/>\nint month &#061; DateUtil.month(date) &#043; 1; \/\/ 10&#xff08;\u6708\u4efd\u4ece0\u5f00\u59cb&#xff09; <\/p>\n<p>1.4 \u96c6\u5408\u5de5\u5177&#xff08;CollUtil&#xff09;<\/p>\n<p>import cn.hutool.core.collection.CollUtil;<\/p>\n<p>List&lt;String&gt; list &#061; CollUtil.newArrayList(&#034;A&#034;, &#034;B&#034;, &#034;C&#034;);<\/p>\n<p>\/\/ \u5224\u7a7a<br \/>\nboolean isEmpty &#061; CollUtil.isEmpty(list); \/\/ false<\/p>\n<p>\/\/ \u96c6\u5408\u64cd\u4f5c<br \/>\nList&lt;String&gt; reversedList &#061; CollUtil.reverse(list); \/\/ [&#034;C&#034;, &#034;B&#034;, &#034;A&#034;]<br \/>\nString joined &#061; CollUtil.join(list, &#034;,&#034;); \/\/ &#034;A,B,C&#034; <\/p>\n<p>2.1 \u6587\u4ef6\u5de5\u5177&#xff08;FileUtil&#xff09;<\/p>\n<p>import cn.hutool.core.io.FileUtil;<\/p>\n<p>\/\/ \u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9<br \/>\nString content &#061; FileUtil.readUtf8String(&#034;test.txt&#034;);<\/p>\n<p>\/\/ \u5199\u5165\u6587\u4ef6<br \/>\nFileUtil.writeUtf8String(&#034;Hello, Hutool!&#034;, &#034;output.txt&#034;);<\/p>\n<p>\/\/ \u6587\u4ef6\u64cd\u4f5c<br \/>\nboolean exists &#061; FileUtil.exist(&#034;test.txt&#034;); \/\/ \u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728<br \/>\nFileUtil.copy(&#034;src.txt&#034;, &#034;dest.txt&#034;, true); \/\/ \u590d\u5236\u6587\u4ef6&#xff08;\u8986\u76d6&#xff09;<br \/>\nFileUtil.del(&#034;temp_dir&#034;); \/\/ \u5220\u9664\u76ee\u5f55 <\/p>\n<p>2.2 \u6d41\u5de5\u5177&#xff08;IoUtil&#xff09;<\/p>\n<p>import cn.hutool.core.io.IoUtil;<\/p>\n<p>\/\/ \u6d41\u62f7\u8d1d&#xff08;\u81ea\u52a8\u5173\u95ed\u6d41&#xff09;<br \/>\ntry (InputStream in &#061; new FileInputStream(&#034;src.txt&#034;);<br \/>\n     OutputStream out &#061; new FileOutputStream(&#034;dest.txt&#034;)) {<br \/>\n    IoUtil.copy(in, out, IoUtil.DEFAULT_BUFFER_SIZE);<br \/>\n} <\/p>\n<p>3.1 \u6458\u8981\u52a0\u5bc6&#xff08;DigestUtil&#xff09;<\/p>\n<p>import cn.hutool.crypto.digest.DigestUtil;<\/p>\n<p>\/\/ MD5<br \/>\nString md5 &#061; DigestUtil.md5Hex(&#034;123456&#034;); \/\/ &#034;e10adc3949ba59abbe56e057f20f883e&#034;<\/p>\n<p>\/\/ SHA-256<br \/>\nString sha256 &#061; DigestUtil.sha256Hex(&#034;123456&#034;);<\/p>\n<p>\/\/ \u52a0\u76d0\u52a0\u5bc6&#xff08;BCrypt&#xff09;<br \/>\nString hashed &#061; BCrypt.hashpw(&#034;password&#034;);<br \/>\nboolean isMatch &#061; BCrypt.checkpw(&#034;password&#034;, hashed); \/\/ \u6821\u9a8c <\/p>\n<p>\u00a03.2 \u5bf9\u79f0\u52a0\u5bc6&#xff08;AES\u3001DES&#xff09;<\/p>\n<p>import cn.hutool.crypto.SecureUtil;<\/p>\n<p>\/\/ AES \u52a0\u5bc6<br \/>\nString key &#061; &#034;1234567890abcdef&#034;; \/\/ 16\/24\/32\u4f4d\u5bc6\u94a5<br \/>\nString encrypted &#061; SecureUtil.aes(key.getBytes()).encryptHex(&#034;Hello&#034;);<br \/>\nString decrypted &#061; SecureUtil.aes(key.getBytes()).decryptStr(encrypted); <\/p>\n<table>\n<tr>\u6a21\u5757\u4e3b\u8981\u529f\u80fd\u5e38\u7528\u7c7b<\/tr>\n<tbody>\n<tr>\n<td>hutool-core<\/td>\n<td>\u5b57\u7b26\u4e32\u3001\u65e5\u671f\u3001\u96c6\u5408\u3001\u6570\u5b57<\/td>\n<td>StrUtil,\u00a0DateUtil,\u00a0CollUtil<\/td>\n<\/tr>\n<tr>\n<td>hutool-http<\/td>\n<td>HTTP \u8bf7\u6c42<\/td>\n<td>HttpUtil<\/td>\n<\/tr>\n<tr>\n<td>hutool-crypto<\/td>\n<td>\u52a0\u5bc6\u89e3\u5bc6&#xff08;MD5\u3001AES\u3001BCrypt&#xff09;<\/td>\n<td>DigestUtil,\u00a0SecureUtil<\/td>\n<\/tr>\n<tr>\n<td>hutool-json<\/td>\n<td>JSON\/XML \u5904\u7406<\/td>\n<td>JSONUtil,\u00a0XmlUtil<\/td>\n<\/tr>\n<tr>\n<td>hutool-extra<\/td>\n<td>\u6587\u4ef6\u3001IO\u3001\u90ae\u4ef6\u7b49<\/td>\n<td>FileUtil,\u00a0MailUtil<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb540\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf16\u6b21\u3002\u8fdb\u884c\u5217\u8868\u663e\u793a\u4e0e\u7528\u6237\u72b6\u6001\u4fee\u6539(\u62c9\u9ed1\u64cd\u4f5c)\u7528\u6237\u5217\u8868\u663e\u793a\u4e3b\u8981\u8fd0\u7528\u4e86\u5206\u9875\u7ba1\u7406\u7ed9\u524d\u7aef\u4f20\u8f93\u6570\u636e(UserVO)\u4ece\u800c\u5728\u9875\u9762\u4e0a\u663e\u793a\u62c9\u9ed1\u64cd\u4f5c,\u6839\u636e\u524d\u7aef\u4f20\u9001\u8fc7\u6765\u7684\u6570\u636e,\u5728\u6570\u636e\u5e93\u4e2d\u6839\u636e\u7528\u6237id\u641c\u7d22\u6b64\u7528\u6237,\u5931\u8d25\u8fd4\u56de\u5f02\u5e38\u6210\u529f\u6267\u884c\u4f5c\u7528\u662f\u628auserDTO\u91cc\u7684\u72b6\u6001\u503c\u8d4b\u7ed9user\u5bf9\u8c61\u5219\u662f\u8ba9\u7f13\u5b58\u4e2d\u7684\u7528\u6237\u72b6\u6001\u4e0e\u65b0\u72b6\u6001\u4fdd\u6301\u4e00\u81f4,\u6267\u884c updateStatus \u51fd\u6570,\u5148\u5237\u65b0\u7528\u6237\u7f13\u5b58,\u4e2d\u4eceRedis\u7f13\u5b58\u4e2d\u83b7\u53d6\u5bf9\u8c61\u5e76\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u4eceredis\u7f13\u5b58\u4e2d\u83b7\u53d6\u6307\u5b9akey\u7684\u5bf9\u8c61,\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u7684\u793a\u4f8b\u3002<\/p>\n","protected":false},"author":2,"featured_media":38442,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-38443","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4) - \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\/38443.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb540\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf16\u6b21\u3002\u8fdb\u884c\u5217\u8868\u663e\u793a\u4e0e\u7528\u6237\u72b6\u6001\u4fee\u6539(\u62c9\u9ed1\u64cd\u4f5c)\u7528\u6237\u5217\u8868\u663e\u793a\u4e3b\u8981\u8fd0\u7528\u4e86\u5206\u9875\u7ba1\u7406\u7ed9\u524d\u7aef\u4f20\u8f93\u6570\u636e(UserVO)\u4ece\u800c\u5728\u9875\u9762\u4e0a\u663e\u793a\u62c9\u9ed1\u64cd\u4f5c,\u6839\u636e\u524d\u7aef\u4f20\u9001\u8fc7\u6765\u7684\u6570\u636e,\u5728\u6570\u636e\u5e93\u4e2d\u6839\u636e\u7528\u6237id\u641c\u7d22\u6b64\u7528\u6237,\u5931\u8d25\u8fd4\u56de\u5f02\u5e38\u6210\u529f\u6267\u884c\u4f5c\u7528\u662f\u628auserDTO\u91cc\u7684\u72b6\u6001\u503c\u8d4b\u7ed9user\u5bf9\u8c61\u5219\u662f\u8ba9\u7f13\u5b58\u4e2d\u7684\u7528\u6237\u72b6\u6001\u4e0e\u65b0\u72b6\u6001\u4fdd\u6301\u4e00\u81f4,\u6267\u884c updateStatus \u51fd\u6570,\u5148\u5237\u65b0\u7528\u6237\u7f13\u5b58,\u4e2d\u4eceRedis\u7f13\u5b58\u4e2d\u83b7\u53d6\u5bf9\u8c61\u5e76\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u4eceredis\u7f13\u5b58\u4e2d\u83b7\u53d6\u6307\u5b9akey\u7684\u5bf9\u8c61,\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u7684\u793a\u4f8b\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38443.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T05:02:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520050237-682c0ced13239.jpg\" \/>\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=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38443.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38443.html\",\"name\":\"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-20T05:02:38+00:00\",\"dateModified\":\"2025-05-20T05:02:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38443.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38443.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38443.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4)\"}]},{\"@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":"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4) - \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\/38443.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb540\u6b21\uff0c\u70b9\u8d5e18\u6b21\uff0c\u6536\u85cf16\u6b21\u3002\u8fdb\u884c\u5217\u8868\u663e\u793a\u4e0e\u7528\u6237\u72b6\u6001\u4fee\u6539(\u62c9\u9ed1\u64cd\u4f5c)\u7528\u6237\u5217\u8868\u663e\u793a\u4e3b\u8981\u8fd0\u7528\u4e86\u5206\u9875\u7ba1\u7406\u7ed9\u524d\u7aef\u4f20\u8f93\u6570\u636e(UserVO)\u4ece\u800c\u5728\u9875\u9762\u4e0a\u663e\u793a\u62c9\u9ed1\u64cd\u4f5c,\u6839\u636e\u524d\u7aef\u4f20\u9001\u8fc7\u6765\u7684\u6570\u636e,\u5728\u6570\u636e\u5e93\u4e2d\u6839\u636e\u7528\u6237id\u641c\u7d22\u6b64\u7528\u6237,\u5931\u8d25\u8fd4\u56de\u5f02\u5e38\u6210\u529f\u6267\u884c\u4f5c\u7528\u662f\u628auserDTO\u91cc\u7684\u72b6\u6001\u503c\u8d4b\u7ed9user\u5bf9\u8c61\u5219\u662f\u8ba9\u7f13\u5b58\u4e2d\u7684\u7528\u6237\u72b6\u6001\u4e0e\u65b0\u72b6\u6001\u4fdd\u6301\u4e00\u81f4,\u6267\u884c updateStatus \u51fd\u6570,\u5148\u5237\u65b0\u7528\u6237\u7f13\u5b58,\u4e2d\u4eceRedis\u7f13\u5b58\u4e2d\u83b7\u53d6\u5bf9\u8c61\u5e76\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u4eceredis\u7f13\u5b58\u4e2d\u83b7\u53d6\u6307\u5b9akey\u7684\u5bf9\u8c61,\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6307\u5b9a\u7c7b\u578b\u7684\u793a\u4f8b\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38443.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-20T05:02:38+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250520050237-682c0ced13239.jpg"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38443.html","url":"https:\/\/www.wsisp.com\/helps\/38443.html","name":"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-20T05:02:38+00:00","dateModified":"2025-05-20T05:02:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38443.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38443.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38443.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5fae\u670d\u52a1\u9879\u76ee-\uff1e\u5728\u7ebfoj\u7cfb\u7edf(Java\u7248 - 4)"}]},{"@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\/38443","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=38443"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38443\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/38442"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38443"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38443"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38443"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}