简体   繁体   English

无法为 ResponseEntity 推断类型 arguments

[英]Cannot infer type arguments for ResponseEntity

I am trying to return the response as string from my function using ResponseEntity but getting an error.我正在尝试使用 ResponseEntity 从我的 function 以字符串形式返回响应,但出现错误。 I tried this:我试过这个:

@GetMapping(value="/getuserip")
public ResponseEntity<Object> getUserData(@RequestParam("username") String userName, HttpServletRequest request){
    String ipAddr = (request.getHeader("X-FORWARDED-FOR"));
    return new ResponseEntity<>(ipAddr, HttpStatus.SC_ACCEPTED);
}

When trying to return the String variable ipAddr I am getting the error.尝试返回字符串变量 ipAddr 时出现错误。 Do you know how to fix this?你知道如何解决这个问题吗?

The library for httpstatus was giving this error in my case.在我的例子中, httpstatus的库给出了这个错误。 Fixed it by replacing org.apache.http.HttpStatus with org.springframework.http.HttpStatus .通过将org.apache.http.HttpStatus替换为org.springframework.http.HttpStatus来修复它。

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

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