springmvc/springboot 自定义响应编码

在开发过程中,受限与所用的框架,跳转到前端 403页面,必须让http 请求 返回http code 为403 ,此时可以使用自定义相应编码

import org.springframework.http.HttpStatus;
    
    
    
    @GetMapping("/selectOne")
    public JsonResult selectOne(@RequestParam( "id") Long id, HttpServletResponse response ) {
        log.info("selectOne id: {}", id);
        // 定义影响状态编码
        response.setStatus(HttpStatus.FORBIDDEN.value());
        return JsonResult.getSuccessResult("sucess");
    }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.