码迷,mamicode.com
首页 > 编程语言 > 详细

Spring rest 可以返回自定义http code

时间:2015-04-02 18:53:01      阅读:378      评论:0      收藏:0      [点我收藏+]

标签:spring   mvc   


参考资料:

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

标签:spring   mvc   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!