java自定义404返回,因为spring 包装的没有code,所以需要自定义返回,spring会在404自动重定向ip:port/error的url

package com.itranswarp.crypto.web.api.v1;

import com.itranswarp.crypto.ApiError;
import com.itranswarp.crypto.bean.ResponseWrapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: wangwu
 * @Date: Created in 11:00 2020-07-02
 * @Description:
 */
@RestController
public class NotPathController {
   @RequestMapping
   public Object error(){
      ResponseWrapper responseWrapper = new ResponseWrapper();
      responseWrapper.setStatus(ResponseWrapper.STATUS_FAIL);
      responseWrapper.setCode(ApiError.PATH_NOT_FOUND.name());
      responseWrapper.setData("");
      return responseWrapper;

   }
}

你可能感兴趣的:(java,spring)