Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从Swapi获取数据https://swapi.co/api/people/ 使用弹簧靴_Java_Spring_Spring Boot_Spring Mvc - Fatal编程技术网

Java 从Swapi获取数据https://swapi.co/api/people/ 使用弹簧靴

Java 从Swapi获取数据https://swapi.co/api/people/ 使用弹簧靴,java,spring,spring-boot,spring-mvc,Java,Spring,Spring Boot,Spring Mvc,当我使用RestTemplate和Getforobject()方法时,我在运行spring引导时收到一个错误代码500。如何使用springboot使用此API package nl.qnh.qforce.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.sp

当我使用RestTemplate和Getforobject()方法时,我在运行spring引导时收到一个错误代码500。如何使用springboot使用此API

package nl.qnh.qforce.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;
import java.util.List;

@RestController
public class PersonController {

    private static String url = "https://swapi.co/api/people/";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/people")
    public List<Object> getPeople(){
        Object[] people = restTemplate.getForObject(url, Object[].class);
        return Arrays.asList(people);
    }
}
包nl.qnh.qforce.controller;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.web.bind.annotation.GetMapping;
导入org.springframework.web.bind.annotation.RestController;
导入org.springframework.web.client.rest模板;
导入java.util.array;
导入java.util.List;
@RestController
公共类个人控制器{
专用静态字符串url=”https://swapi.co/api/people/";
@自动连线
私有RestTemplate RestTemplate;
@GetMapping(“/people”)
公共列表getPeople(){
Object[]people=restemplate.getForObject(url,Object[].class);
返回数组.asList(人);
}
}

我建议首先检查手动调用提供的url是否返回预期响应。您可以使用curl、postman或任何其他类似工具。如果对提供的url的调用返回响应,请向我们提供应用程序中的更多上下文,以便我们可以评估500个错误是由哪个部分造成的。

尝试使用java.net.HttpURLConnection获取结果。嘿,您解决了问题吗?