Spring Boot-Rest Service-获取随机HTTP状态400 [英] Spring boot - Rest Service - Getting random HTTP status 400

查看:112
本文介绍了Spring Boot-Rest Service-获取随机HTTP状态400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到原因...但是我随机得到Http 400,参数不存在:

I could not find why is the cause ... but I am getting randomly Http 400, param not present:

Required String parameter 'id' is not present. 

我在邮递员和其他Rest Client中得到此消息,

I am getting this in Postman and different Rest Client,

这是我的代码:

 @RequestMapping(path = "/borrower", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
   @CrossOrigin(origins = "*")
    public ResponseEntity<?> borrower(@RequestParam(value = "id") String cuit, @RequestHeader("Authorization") String token)  throws Exception {

           // some business code
       return ResponseEntity.ok().build();
    }

我正在使用Spring Boot 2.0.1

I'm using Spring boot 2.0.1

推荐答案

如果尝试该怎么办像这样?

What if you try it like this?

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> getStuff(@PathVariable("id") long id) { 
    //the long id defined is the variable passed when making the petition through postman
    Entity entity =  entityService.getById(id);
    //for the entity it is supposed to be your model, and service
    if (entity == null) {
        return new ResponseEntity<ErrorDTO>(new ErrorDTO(
         // the ErrorDTO is a file where you get all the descriptions
                "did not find any id  " + id), HttpStatus.NOT_FOUND);

    }
    return new ResponseEntity<Entity>(entity, HttpStatus.OK);

}

因为我有一些反对意见,我无法发表评论,人们听不懂我说的话..换句话说,它是这样的。.编辑

Because i've got some downvotes i'm not able to comment and people didn't understood what i said.. so in other words it goes like this.. EDITED

这篇关于Spring Boot-Rest Service-获取随机HTTP状态400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆