当前位置:   article > 正文

controller 等接口调用 url_java controller怎么打开url请求

java controller怎么打开url请求

接口冲突

排查方法

看镜像版本
curl pod_ip:pod_port/服务名/请求路径 -H "请求头" -d '参数'
		或者 curl server_ip:server_port/服务名/请求路径 -H "请求头" -d '参数'
  • 1
  • 2
  • 3

几种情况

两种情况

相同 请求方法,相同 请求路径 冲突了
不同 请求方法,相同 请求路径 冲突了 
  • 1
  • 2
  • 3
  • 4
两个服务器上 一个冲突了,一个没冲突 :两个服务器 打包版本不一致
  • 1
隐藏情况:
两个服务器上 一个冲突了,一个没冲突 ,但是两个服务器,服务版本一致

检查 服务 中是不是调用了另一个服务 -> 另一个服务 版本不一致
  • 1
  • 2
  • 3
  • 4

以下两个接口在调用时会产生冲突

例如 postman 调用下面接口时
http://localhost:8080/myweb/companyList

会报错,只能使用 get 方法
原因是 和下面的 post 方法 url 冲突了
  • 1
  • 2
  • 3
  • 4
  • 5
@ApiOperation(value = "用户详情", notes = "用户详情", httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "/{platformSerial}")
public DeferredResult<ResponseEntity<BaseResult<PlatformVo>>> userDetail(@ApiParam(value = "用户编号", required = true) @PathVariable("userSerial") String userSerial) {
    return ok(userServiceApi.userDetail(userSerial));
}

@ApiOperation(value = "公司信息列表", notes = "公司信息列表", httpMethod = "POST")
@PostMapping(value = "/companyList")
public DeferredResult<ResponseEntity<BaseResult<CompanyInfo>>> companyInfo(@Valid @RequestBody CompanyFilterRequest request) {
    return ok(companyServiceApi.companyList(request));
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
post url 方法改为 即可避免冲突
@PostMapping(value = "/company/ist")
  • 1
  • 2

示例二

下面接口会冲突

@RestController
 public class StudentController {
 @RequestMapping(value = "/student/detail/{id}/{name}")
    public Object student2(@PathVariable("id") Integer id,  
    @PathVariable("name") String name){
        ...
        return student;
    }
    
    @RequestMapping(value = "/student/detail/{id}/{detail}")
    public Object student3(@PathVariable("id") Integer id, 
    @PathVariable("detail") String detail){
        ...
        return student;
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

方案一:将@RequestMapping改成PostMapping或者@DeleteMapping等注解

@PostMapping(value = "/student/detail/{id}/{detail}")
public Object student3(@PathVariable("id") Integer id,
					@PathVariable("detail") String detail){
	  ...
	  return student;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

方案二:改变请求路径

@RequestMapping(value = "/student/{id}/detail/{detail}")
public Object student3(@PathVariable("id") Integer id,
@PathVariable("detail") String detail){
    ...
    return student;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/302697
推荐阅读
相关标签
  

闽ICP备14008679号