spring web PostMapping ,RequestMapping, 全局日志

注解来自于 spring-web-5.3.21.jar

例子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) {

例子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) {

get发送的时候 ,可以在body里填数据么?

全局监控

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


    /**
     * 处理自定义的业务异常
     * @param req
     * @param e
     * @return
     */
    @ExceptionHandler(value = BizException.class)
    @ResponseBody
    public BaseRep bizExceptionHandler(HttpServletRequest req, BizException e){
        LogUtil.error(LOGGER,e,"发生异常!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());
       
相关推荐
noBt11 分钟前
Windows IDEA 卡顿严重
java·ide·intellij-idea
h7ml14 分钟前
淘宝返利软件的跨端同步架构:Java RESTful API+GraphQL满足Web/APP/小程序的多端数据需求
java·架构·restful
会编程的土豆14 分钟前
新手前端小细节
前端·css·html·项目
shuair17 分钟前
redis缓存预热、缓存击穿、缓存穿透、缓存雪崩
redis·spring·缓存
qq_3363139317 分钟前
javaweb-web基础(springboot入门)
java·开发语言·mysql
闻哥19 分钟前
从测试坏味道到优雅实践:打造高质量单元测试
java·面试·单元测试·log4j·springboot
smileNicky19 分钟前
统一网关的登录流程总结
java
计算机程序设计小李同学31 分钟前
基于 Spring Boot + Vue 的龙虾专营店管理系统的设计与实现
java·spring boot·后端·spring·vue
广州华水科技33 分钟前
单北斗GNSS在桥梁形变监测中的应用与技术进展分析
前端
我讲个笑话你可别哭啊34 分钟前
鸿蒙ArkTS快速入门
前端·ts·arkts·鸿蒙·方舟开发框架