简体   繁体   English

Spring Boot-Rest Service-获取随机HTTP状态400

[英]Spring boot - Rest Service - Getting random HTTP status 400

I could not find why is the cause ... but I am getting randomly Http 400, param not present: 我找不到原因。。。但是我随机得到Http 400,参数不存在:

Required String parameter 'id' is not present. 

I am getting this in Postman and different Rest Client, 我在邮递员和其他Rest Client中得到这个,

this is my code : 这是我的代码:

 @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();
    }

I'm using Spring boot 2.0.1 我正在使用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 因为我有一些反对意见,所以我无法发表评论,人们也听不懂我说的话。换句话说,它像这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM