mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
添加全局响应包装
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -65,6 +65,11 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.lihongjie.coal.config;
|
||||
|
||||
import cn.lihongjie.coal.dto.R;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class RResponseBodyAdvice implements ResponseBodyAdvice<Object> {
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
|
||||
|
||||
if (!selectedContentType.includes(MediaType.APPLICATION_JSON)) {
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
if (body instanceof R<?>) {
|
||||
return body;
|
||||
}
|
||||
|
||||
return R.success(body);
|
||||
}
|
||||
}
|
||||
@@ -26,17 +26,16 @@ public class CoalController {
|
||||
|
||||
|
||||
@PostMapping("/blend")
|
||||
public R<CoalBlendResult> blend(@RequestBody CoalBlendRequest request){
|
||||
public CoalBlendResult blend(@RequestBody CoalBlendRequest request){
|
||||
|
||||
return R.success(coalService.blend(request));
|
||||
return coalService.blend(request);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/params")
|
||||
public R<List<CoalParameterDef>> params(){
|
||||
public List<CoalParameterDef> params(){
|
||||
|
||||
throw new BizException();
|
||||
// return R.success(coalService.paramDefs());
|
||||
return coalService.paramDefs();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user