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());
       
相关推荐
apocelipes1 小时前
golang unique包和字符串内部化
java·python·性能优化·golang
Full Stack Developme2 小时前
java.text 包详解
java·开发语言·python
哆啦A梦15882 小时前
搜索页面布局
前端·vue.js·node.js
_院长大人_2 小时前
el-table-column show-overflow-tooltip 只能显示纯文本,无法渲染 <p> 标签
前端·javascript·vue.js
刘梦凡呀3 小时前
C#获取钉钉平台考勤记录
java·c#·钉钉
best_virtuoso3 小时前
PostgreSQL 常见数组操作函数语法、功能
java·数据结构·postgresql
yudiandian20143 小时前
02 Oracle JDK 下载及配置(解压缩版)
java·开发语言
楚韵天工4 小时前
宠物服务平台(程序+文档)
java·网络·数据库·spring cloud·编辑器·intellij-idea·宠物
helloworddm4 小时前
Orleans Stream SubscriptionId 生成机制详解
java·系统架构·c#
失散134 小时前
分布式专题——43 ElasticSearch概述
java·分布式·elasticsearch·架构