forked from YunaiV/yudao-cloud
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
将使用手机号进行注册登陆的逻辑,进行变更~
- Loading branch information
YunaiV
committed
Feb 25, 2019
1 parent
4ae211d
commit 4162eda
Showing
27 changed files
with
351 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*.iws | ||
*.iml | ||
*.ipr | ||
target/* | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
common/common-framework/src/main/java/cn/iocoder/common/framework/util/ExceptionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cn.iocoder.common.framework.util; | ||
|
||
import cn.iocoder.common.framework.exception.ServiceException; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.UndeclaredThrowableException; | ||
|
||
public class ExceptionUtil { | ||
|
||
public static ServiceException getServiceException(Exception e) { | ||
if (e instanceof UndeclaredThrowableException) { | ||
return getServiceException((UndeclaredThrowableException) e); | ||
} | ||
return null; | ||
} | ||
|
||
// 处理 Spring 动态代理调用时,发生 UndeclaredThrowableException 的情况。 | ||
// 不了解的胖友,可以先看看 https://segmentfault.com/a/1190000012262244 文章 | ||
// 原因是: | ||
// 1. Dubbo 动态代理 Wrapper 会将抛出的异常,包装成 InvocationTargetException 异常 | ||
// 2. Spring AOP 发现是 InvocationTargetException 异常是非方法定义的异常,则会包装成 UndeclaredThrowableException 异常。 | ||
public static ServiceException getServiceException(UndeclaredThrowableException e) { | ||
Throwable undeclaredThrowable = e.getUndeclaredThrowable(); | ||
if (undeclaredThrowable instanceof InvocationTargetException) { | ||
InvocationTargetException invocationTargetException = (InvocationTargetException) undeclaredThrowable; | ||
Throwable targetException = invocationTargetException.getTargetException(); | ||
if (targetException != null & targetException instanceof ServiceException) { | ||
return (ServiceException) targetException; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
common/common-framework/src/main/java/cn/iocoder/common/framework/vo/CommonResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package cn.iocoder.common.framework.vo; | ||
|
||
import org.springframework.util.Assert; | ||
|
||
public class CommonResult<T> { | ||
|
||
public static Integer CODE_SUCCESS = 0; | ||
|
||
/** | ||
* 错误码 | ||
*/ | ||
private Integer code; | ||
/** | ||
* 错误提示 | ||
*/ | ||
private String message; | ||
/** | ||
* 返回数据 | ||
*/ | ||
private T data; | ||
|
||
/** | ||
* 将传入的 result 对象,转换成另外一个泛型结果的对象 | ||
* | ||
* 因为 A 方法返回的 CommonResult 对象,不满足调用其的 B 方法的返回,所以需要进行转换。 | ||
* | ||
* @param result 传入的 result 对象 | ||
* @param <T> 返回的泛型 | ||
* @return 新的 CommonResult 对象 | ||
*/ | ||
public static <T> CommonResult<T> error(CommonResult<?> result) { | ||
return error(result.getCode(), result.getMessage()); | ||
} | ||
|
||
public static <T> CommonResult<T> error(Integer code, String message) { | ||
Assert.isTrue(!CODE_SUCCESS.equals(code), "code 必须是错误的!"); | ||
CommonResult<T> result = new CommonResult<>(); | ||
result.code = code; | ||
result.message = message; | ||
return result; | ||
} | ||
|
||
public static <T> CommonResult<T> success(T data) { | ||
CommonResult<T> result = new CommonResult<>(); | ||
result.code = CODE_SUCCESS; | ||
result.data = data; | ||
result.message = ""; | ||
return result; | ||
} | ||
|
||
public Integer getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(Integer code) { | ||
this.code = code; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public void setMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
public T getData() { | ||
return data; | ||
} | ||
|
||
public void setData(T data) { | ||
this.data = data; | ||
} | ||
|
||
public boolean isSuccess() { | ||
return CODE_SUCCESS.equals(code); | ||
} | ||
|
||
public boolean isError() { | ||
return !isSuccess(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,5 @@ public Object getData() { | |
public void setData(Object data) { | ||
this.data = data; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
user/user-application/src/main/java/cn/iocoder/mall/user/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package cn.iocoder.mall.user.controller; | ||
|
||
import cn.iocoder.mall.user.sdk.context.SecurityContextHolder; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
//@RestController | ||
//@RequestMapping("/user") | ||
@RestController | ||
@RequestMapping("/user") | ||
public class UserController { | ||
|
||
@GetMapping("/info") | ||
public Long info() { | ||
// TODO 芋艿,正在实现中 | ||
// return SecurityContextHolder.getContext().getUid(); | ||
return null; | ||
return SecurityContextHolder.getContext().getUid(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.