Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
f3b95e44
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f3b95e44
编写于
9月 09, 2020
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
web
上级
16369e7a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
19 addition
and
77 deletion
+19
-77
whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java
...java/org/hongxi/whatsmars/common/result/ResultHelper.java
+4
-0
whatsmars-mq/whatsmars-mq-kafka/src/main/resources/application.yml
...-mq/whatsmars-mq-kafka/src/main/resources/application.yml
+4
-1
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/controller/SampleController.java
...hatsmars/boot/sample/web/controller/SampleController.java
+5
-4
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java
...rs/boot/sample/web/exception/DefaultExceptionHandler.java
+6
-5
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/model/JsonResponse.java
.../hongxi/whatsmars/boot/sample/web/model/JsonResponse.java
+0
-67
未找到文件。
whatsmars-common/src/main/java/org/hongxi/whatsmars/common/result/ResultHelper.java
浏览文件 @
f3b95e44
...
...
@@ -31,4 +31,8 @@ public class ResultHelper {
}
}
public
static
Result
newResult
(
int
code
,
String
message
)
{
return
new
Result
(
code
,
message
);
}
}
whatsmars-mq/whatsmars-mq-kafka/src/main/resources/application.yml
浏览文件 @
f3b95e44
spring
:
kafka
:
bootstrap-servers
:
127.0.0.1:9092
producer
:
value-serializer
:
consumer
:
group-id
:
testGroup
auto-offset-reset
:
earliest
\ No newline at end of file
auto-offset-reset
:
earliest
value-deserializer
:
\ No newline at end of file
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/controller/SampleController.java
浏览文件 @
f3b95e44
package
org.hongxi.whatsmars.boot.sample.web.controller
;
import
org.hongxi.whatsmars.boot.sample.web.model.JsonResponse
;
import
org.hongxi.whatsmars.common.result.Result
;
import
org.hongxi.whatsmars.common.result.ResultHelper
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
...
...
@@ -14,9 +15,9 @@ import org.springframework.web.bind.annotation.RestController;
public
class
SampleController
{
@GetMapping
(
"/hello"
)
public
JsonResponse
<
String
>
hello
(
@RequestParam
String
userId
,
@RequestParam
Integer
age
)
{
public
Result
<
String
>
hello
(
@RequestParam
String
userId
,
@RequestParam
Integer
age
)
{
String
hello
=
userId
+
","
+
age
;
return
JsonResponse
.
success
(
hello
);
return
ResultHelper
.
newSuccessResult
(
hello
);
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/exception/DefaultExceptionHandler.java
浏览文件 @
f3b95e44
package
org.hongxi.whatsmars.boot.sample.web.exception
;
import
lombok.extern.slf4j.Slf4j
;
import
org.hongxi.whatsmars.boot.sample.web.model.JsonResponse
;
import
org.hongxi.whatsmars.common.result.Result
;
import
org.hongxi.whatsmars.common.result.ResultHelper
;
import
org.springframework.core.annotation.AnnotationUtils
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
...
...
@@ -21,19 +22,19 @@ public class DefaultExceptionHandler {
@ResponseStatus
(
HttpStatus
.
OK
)
@ExceptionHandler
(
BusinessException
.
class
)
@ResponseBody
public
JsonResponse
handleLogicException
(
HttpServletRequest
request
,
BusinessException
e
)
{
public
Result
handleLogicException
(
HttpServletRequest
request
,
BusinessException
e
)
{
log
.
error
(
"business exception handled, request:{}"
,
request
.
getRequestURI
(),
e
);
return
JsonResponse
.
error
(
e
.
getCode
(),
e
.
getMsg
());
return
ResultHelper
.
newResult
(
e
.
getCode
(),
e
.
getMsg
());
}
@ResponseStatus
(
HttpStatus
.
OK
)
@ExceptionHandler
(
Exception
.
class
)
@ResponseBody
public
JsonResponse
handleException
(
HttpServletRequest
request
,
Exception
e
)
throws
Exception
{
public
Result
handleException
(
HttpServletRequest
request
,
Exception
e
)
throws
Exception
{
if
(
AnnotationUtils
.
findAnnotation
(
e
.
getClass
(),
ResponseStatus
.
class
)
!=
null
)
{
throw
e
;
}
log
.
error
(
"exception handled, request:{}"
,
request
.
getRequestURI
(),
e
);
return
JsonResponse
.
error
(
500
,
e
.
getMessage
());
return
ResultHelper
.
newResult
(
500
,
e
.
getMessage
());
}
}
whatsmars-spring-boot-samples/whatsmars-boot-sample-web/src/main/java/org/hongxi/whatsmars/boot/sample/web/model/JsonResponse.java
已删除
100644 → 0
浏览文件 @
16369e7a
package
org.hongxi.whatsmars.boot.sample.web.model
;
/**
* Created by shenhongxi on 2020/8/16.
*/
public
class
JsonResponse
<
T
>
{
public
static
final
int
SUCCESS_CODE
=
0
;
// 错误码,0表示成功
private
int
code
;
// 错误原因
private
String
msg
;
// 服务器下发数据时间
private
long
millisecond
;
private
T
data
;
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
public
long
getMillisecond
()
{
return
millisecond
;
}
public
void
setMillisecond
(
long
millisecond
)
{
this
.
millisecond
=
millisecond
;
}
public
T
getData
()
{
return
data
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
public
static
<
T
>
JsonResponse
success
(
T
value
)
{
JsonResponse
<
T
>
response
=
new
JsonResponse
<>();
response
.
setCode
(
SUCCESS_CODE
);
response
.
setMsg
(
"ok"
);
response
.
setMillisecond
(
System
.
currentTimeMillis
());
response
.
setData
(
value
);
return
response
;
}
public
static
JsonResponse
error
(
int
ec
,
String
em
)
{
JsonResponse
response
=
new
JsonResponse
<>();
response
.
setCode
(
ec
);
response
.
setMsg
(
em
);
response
.
setMillisecond
(
System
.
currentTimeMillis
());
return
response
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录