Java Spring启动-Rest服务-获取随机HTTP状态400
我找不到原因是什么。。。但我随机得到Http 400,参数不存在:Java Spring启动-Rest服务-获取随机HTTP状态400,java,spring-boot,postman,Java,Spring Boot,Postman,我找不到原因是什么。。。但我随机得到Http 400,参数不存在: Required String parameter 'id' is not present. 我在邮递员和不同的Rest客户那里得到这个 这是我的代码: @RequestMapping(path = "/borrower", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @CrossOrigin(o
Required String parameter 'id' is not present.
我在邮递员和不同的Rest客户那里得到这个
这是我的代码:
@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();
}
@RequestMapping(path=“/借款人”,method=RequestMethod.GET,products=MediaType.APPLICATION\u JSON\u VALUE)
@交叉原点(原点=“*”)
公共响应借方(@RequestParam(value=“id”)字符串cuit、@RequestHeader(“授权”)字符串令牌)引发异常{
//一些商业代码
返回ResponseEntity.ok().build();
}
我使用的是SpringBoot2.0.1
如果你这样尝试会怎么样
@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);
}
@RequestMapping(value=“/{id}”,method=RequestMethod.GET)
公共响应属性getStuff(@PathVariable(“id”)long id){
//定义的long id是通过邮递员提交申请时传递的变量
实体=entityService.getById(id);
//对于实体,它应该是您的模型和服务
if(实体==null){
返回新响应(新错误到(
//ErrorDTO是一个文件,您可以在其中获取所有描述
“未找到任何id”+id),HttpStatus.not_FOUND);
}
返回新的响应属性(实体,HttpStatus.OK);
}
因为我投了一些反对票,所以我无法发表评论,人们也不理解我说的话。。换句话说就是这样。。已编辑如果将传入参数从
cuit
重命名为id
,会发生什么情况?(在借款人(…)
方法签名中)我可以试试。你确定你的代码可以编译吗?@MarkoPacak作为第一步,一如既往,尝试将@ResponseBody
放在返回类型ResponseBody
欢迎@Cesar Kemper之前,请描述你的解决方案:)。