小编Ben*_*Ben的帖子

用于解析JSON的简单Spring代码

我是一个春天的新手.编写非常简单的代码,从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)

java spring json

11
推荐指数
1
解决办法
4万
查看次数

循环视图路径错误,Spring MVC

我正在尝试做教程 - > 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)

java spring view spring-mvc

4
推荐指数
1
解决办法
8257
查看次数

标签 统计

java ×2

spring ×2

json ×1

spring-mvc ×1

view ×1