首页 > 编程语言 > 详细

Spring rest 可以返回自定义http code

时间:2015-04-02 18:52:56      阅读:185      评论:0      收藏:0      [点我收藏+]


参考资料:

http://stackoverflow.com/questions/16232833/how-to-respond-with-http-400-error-in-a-spring-mvc-responsebody-method-returnin#comment23256806_16250729


@RequestMapping(value = "/matches/{matchId}", produces = "application/json")
@ResponseBody
public String match(@PathVariable String matchId, @RequestBody String body,
            HttpServletRequest request, HttpServletResponse response) {
    String json = matchService.getMatchJson(matchId);
    if (json == null) {
        response.setStatus( HttpServletResponse.SC_BAD_REQUEST  );
    }
    return json;
}

Spring rest 可以返回自定义http code

原文:http://blog.csdn.net/zhangming1013/article/details/44835409

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!