首页 > 解决方案 > 通过 postgres 使用 d3.js

问题描述

我目前正在学习 java spring 和 d3.js。并且发现自己遇到了障碍,因为经过无数次反复试验和研究,我似乎无法找到问题的正确答案。

下面的代码是我的控制器:

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import dashboard.atmandcam.model.MyModel;
import dashboard.atmandcam.repo.MyRepo;

@RestController
public class MyController {

    @Autowired
    private MyRepo myRepo;

    @GetMapping("/test")
    public String sayHi() {
        return "hi";
    }

    @GetMapping("/queries")
    public List<MyModel> getResult(){
        return myRepo.getQueryResult();
    }

    @GetMapping("/queries/{id}")
    public List<MyModel> getSpecific(@PathVariable String id){
        return myRepo.getSpecificResult(id);
    }
}

然后这是我的 d3.js

var url = "/queries/31370100";
d3.json(url, function(data) {
  console.log(data);
});

我的控制器的结果是带有 URL(http://localhost:9090/queries/31370100): JSON 结果

我想知道如何在 d3.js 中使用我的 url 上的 JSON,以便我可以围绕我的数据库构建图表。

标签: javascriptjavajsonspring-bootd3.js

解决方案


推荐阅读