Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
40516d95
mica
项目概览
mica
/
mica
通知
10
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
40516d95
编写于
5月 17, 2021
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
mica-core R 添加 throwOn 系列方法。
上级
575a568b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
0 deletion
+46
-0
CHANGELOG.md
CHANGELOG.md
+1
-0
mica-core/src/main/java/net/dreamlu/mica/core/result/R.java
mica-core/src/main/java/net/dreamlu/mica/core/result/R.java
+45
-0
未找到文件。
CHANGELOG.md
浏览文件 @
40516d95
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
-
:sparkles: mica-ip2region、mica-captcha 添加对 spring-native 的支持 #38 #I3PX2N
-
:sparkles: mica-ip2region、mica-captcha 添加对 spring-native 的支持 #38 #I3PX2N
-
:sparkles: mica-jetcache 完善 metrics 待续 #37 #I3PX2K
-
:sparkles: mica-jetcache 完善 metrics 待续 #37 #I3PX2K
-
:sparkles: mica-caffeine 添加不支持自定义 Caffeine bean 提示。
-
:sparkles: mica-caffeine 添加不支持自定义 Caffeine bean 提示。
-
:sparkles: mica-core R 添加 throwOn 系列方法。
-
:bug: mica-logging 修复 LoggingInitializer Spring boot 2.4.x 失效的问题。
-
:bug: mica-logging 修复 LoggingInitializer Spring boot 2.4.x 失效的问题。
-
:arrow_up: 升级 druid 到 1.2.6
-
:arrow_up: 升级 druid 到 1.2.6
...
...
mica-core/src/main/java/net/dreamlu/mica/core/result/R.java
浏览文件 @
40516d95
...
@@ -27,6 +27,8 @@ import org.springframework.lang.Nullable;
...
@@ -27,6 +27,8 @@ import org.springframework.lang.Nullable;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.function.Function
;
import
java.util.function.Predicate
;
/**
/**
* 响应信息主体
* 响应信息主体
...
@@ -187,6 +189,49 @@ public class R<T> implements Serializable {
...
@@ -187,6 +189,49 @@ public class R<T> implements Serializable {
return
new
R
<>(
rCode
,
msg
);
return
new
R
<>(
rCode
,
msg
);
}
}
/**
* 断言 成功时:直接抛出失败异常,返回传入的 result。
*
* @param predicate 断言函数
* @param object 模型
* @param result 响应对象
* @param <T> 泛型
*/
public
static
<
T
>
void
throwOn
(
Predicate
<
T
>
predicate
,
T
object
,
R
<?>
result
)
{
if
(
predicate
.
test
(
object
))
{
throw
new
ServiceException
(
result
);
}
}
/**
* 断言 成功时:直接抛出失败异常,返回传入的 result。
*
* @param predicate 断言函数
* @param object 模型
* @param rCode 响应 code
* @param <T> 泛型
*/
public
static
<
T
>
void
throwOn
(
Predicate
<
T
>
predicate
,
T
object
,
IResultCode
rCode
)
{
if
(
predicate
.
test
(
object
))
{
throw
new
ServiceException
(
rCode
);
}
}
/**
* 断言 成功时:直接抛出失败异常,返回传入的 result。
*
* @param predicate 断言函数
* @param object 模型
* @param rCode 响应 code
* @param msg 自定义消息
* @param <T> 泛型
*/
public
static
<
T
>
void
throwOn
(
Predicate
<
T
>
predicate
,
T
object
,
IResultCode
rCode
,
String
msg
)
{
if
(
predicate
.
test
(
object
))
{
throw
new
ServiceException
(
rCode
,
msg
);
}
}
/**
/**
* 当 result 不成功时:直接抛出失败异常,返回传入的 result。
* 当 result 不成功时:直接抛出失败异常,返回传入的 result。
*
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录