修改了 restful 实例
This commit is contained in:
@ -0,0 +1,23 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.restful.example.advice;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHanlder extends ResponseEntityExceptionHandler {
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public ResponseEntity<Object> handleRuntimeException(RuntimeException ex, WebRequest request) {
|
||||
log.error("500 Status Code.", ex);
|
||||
|
||||
return new ResponseEntity<>(ex.getMessage(), new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
@ -1,24 +1,23 @@
|
||||
package com.chinaunicom.mall.ebtp.cloud.restful.example.controller;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.chinaunicom.mall.ebtp.cloud.mvc.starter.base.BaseResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/simple", method = RequestMethod.POST)
|
||||
public class SimpleController {
|
||||
|
||||
@RequestMapping("/hello")
|
||||
public BaseResponse<String> hello() {
|
||||
return BaseResponse.success("Hello Spring Rest");
|
||||
public ResponseEntity<String> hello() {
|
||||
return ResponseEntity.ok("Hello Spring Rest");
|
||||
}
|
||||
|
||||
@RequestMapping("/echo/{message}")
|
||||
public BaseResponse<String> echo(@PathVariable String message) {
|
||||
return BaseResponse.success(message);
|
||||
public ResponseEntity<String> echo(@PathVariable String message) {
|
||||
return ResponseEntity.ok(message);
|
||||
}
|
||||
|
||||
@RequestMapping("/error")
|
||||
|
Reference in New Issue
Block a user