spring web PostMapping, RequestMapping, global log

Annotations come from spring-web-5.3.21.jar


Example 1

@RestController
@RequestMapping("/v1/alg")
public class AlgController {
  
  

@PostMapping(value = "/task/{taskNo}", produces = "application/json; charset=utf-8")
@ResponseBody
public BaseRep<Boolean> insertTaskResult(
        @PathVariable @NotBlank String taskNo,
        @RequestBody Object result) {



Example 2

@Controller
@RequestMapping("")
public class GatewayController {

 @RequestMapping(value = "/proxy", method = { RequestMethod.GET,
                                                 RequestMethod.POST }, produces = "application/json; charset=utf-8")
    @ResponseBody
    @SkipXss
    public BaseResponse<Object> proxy(@RequestParam(value = "facade") String facade,
                                      @RequestParam(value = "method") String method,
                                      @RequestParam(value = "paramJson") String paramJson,
                                      @RequestParam(value = "env") String env) {

Can you fill in the data in the body when the get is sent?

Global monitoring

@ControllerAdvice 
public class GlobalExceptionHandler { 
    private static final Logger LOGGER = LoggerFactory.getLogger(GlobalExceptionHandler.class); 


    /** 
     * Handle custom business exceptions 
     * @param req 
     * @param e 
     * @return 
     */ 
    @ExceptionHandler(value = BizException .class) 
    @ResponseBody 
    public BaseRep bizExceptionHandler(HttpServletRequest req, BizException e){ 
        LogUtil.error(LOGGER,e,"An exception occurred! BizException,code="+e.getErrorEnum()+",msg="+e.getMessage( )); 
        BaseRep baseRep = new BaseRep(); 
        baseRep.setSuccess(false); 
        baseRep.setResultCode(e.getErrorEnum().getCode()); 
        baseRep.setResultMessage(e.getErrorEnum().getDesc());
        return baseRep;
    }

    /**
     * 处理其他异常
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = Throwable.class)
    @ResponseBody
    public BaseRep exceptionHandler(HttpServletRequest req, Throwable e) throws IOException {
        LogUtil.error(LOGGER,e,"异常!Throwable,req="+req.getRequestURL()+",input="+req.getInputStream()+",msg="+e.getMessage());
       

Guess you like

Origin blog.csdn.net/fei33423/article/details/131828785