如果你想把返回的结果输出到本地csv文件里,你可以使用java.io包中的类来操作文件,比如FileWriter,BufferedWriter,PrintWriter等。你可以把返回的结果转换成逗号分隔的字符串,然后写入到文件中。请参考以下代码³:
“`java
// request url
String url = “https://example.com/api?name={name}&age={age}”;
// create an instance of RestTemplate
RestTemplate restTemplate = new RestTemplate();
// create a map for url parameters
Map<String, String> params = new HashMap<>();
params.put(“name”, “张三”);
params.put(“age”, “25”);
// make an HTTP GET request with parameters
String result = restTemplate.getForObject(url, String.class, params);
// print result
System.out.println(result);
// create a csv file
File csvFile = new File(“result.csv”);
// create a writer
try (PrintWriter writer = new PrintWriter(csvFile)) {
// write result to file
writer.println(result);
} catch (IOException e) {
// handle exception
e.printStackTrace();
}
“`