我是一个春天的新手.编写非常简单的代码,从http://api.engin.umich.edu/hostinfo/...PONT&room=B505的API调用中获取JSON对象数组
只获取"名称:NULL"
import org.springframework.web.client.RestTemplate;
public class Application {
public static void main(String args[]) {
RestTemplate restTemplate = new RestTemplate();
Computer[] computer = restTemplate.getForObject("http://api.engin.umich.edu/hostinfo/v1/computers.json?building=PIERPONT&room=B505", Computer[].class);
System.out.println("Name: " + computer[0].getName());
}
}
Run Code Online (Sandbox Code Playgroud)
这是简单的计算机课程.
package hello;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Computer {
private String hostname;
public String getName() {
return hostname;
}
public String toString() {
return "Computer [hostname=" + hostname + "]";
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试做教程 - > http://spring.io/guides/gs/serving-web-content/
当我运行它,它说圆形视图路径[问候],为什么?
在本教程中,我不明白的一件事是以下内容以及它的工作原理:
return "greeting";
Run Code Online (Sandbox Code Playgroud)
代码段:
package hello;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class GreetingController {
@RequestMapping("/greeting")
public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "greeting";
}
}
Run Code Online (Sandbox Code Playgroud)