From afe4128893eaf379111d8f402be712aa180449d7 Mon Sep 17 00:00:00 2001 From: 31353 <31353751672@qq.com> Date: Mon, 8 Jan 2024 09:22:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E5=9B=9B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/encodings.xml | 3 ++ .../bwie/service/impl/AuthServicelmpl.java | 30 +++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.idea/encodings.xml b/.idea/encodings.xml index bc0034f..fb60218 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,6 +1,9 @@ + + + diff --git a/bwie-auth/src/main/java/com/bwie/service/impl/AuthServicelmpl.java b/bwie-auth/src/main/java/com/bwie/service/impl/AuthServicelmpl.java index 88871a8..69c204e 100644 --- a/bwie-auth/src/main/java/com/bwie/service/impl/AuthServicelmpl.java +++ b/bwie-auth/src/main/java/com/bwie/service/impl/AuthServicelmpl.java @@ -48,13 +48,11 @@ public class AuthServicelmpl implements AuthService{ public Result login(UserRequest userRequest) { //判断姓名是否为空 Optional optional = Optional.ofNullable(userRequest.getUsername()); - + String defaultName = optional.orElse("张三"); //判断 - if (!optional.isPresent()){ - //为null定义一个默认值 - String defaultName = optional.orElse("张三"); - userRequest.setUsername(defaultName); - } + String orDefault = optionalUtils.getOrDefault(optional, defaultName); + //为null 返回默认值 + userRequest.setUsername(orDefault); User user = remoteUserService.findName(userRequest.getUsername()).getData(); if (null==user){ return Result.error("用户名不存在!!!!!!!"); @@ -75,11 +73,10 @@ public class AuthServicelmpl implements AuthService{ public Result sendCode(String tel) { //判断手机号是否为空 Optional optional = Optional.ofNullable(tel); - if (!optional.isPresent()){ - //默认值 - String defaultPhone = optional.orElse("18098734205"); - tel = defaultPhone; - } + //默认值 + String defaultPhone = optional.orElse("18098734205"); + String defaultTel = optionalUtils.getOrDefault(optional, defaultPhone); + tel = defaultTel; //格式验证 if (!tel.matches("^1[3-9]\\d{9}$")){ return Result.error("手机号格式有误"); @@ -105,11 +102,12 @@ public class AuthServicelmpl implements AuthService{ public Result TelLogin(TelLogin telLogin) { //判断手机号是否为空 Optional optional = Optional.ofNullable(telLogin.getTel()); - if (!optional.isPresent()){ - //默认值 - String defaultPhone = optional.orElse("18098734205"); - telLogin.setTel(defaultPhone); - } + //默认值 + String defaultPhone = optional.orElse("18098734205"); + + String orDefault = optionalUtils.getOrDefault(optional, defaultPhone); + + telLogin.setTel(orDefault); //格式验证 if (!telLogin.getTel().matches("^1[3-9]\\d{9}$")){ return Result.error("手机号格式有误");