【发布时间】:2018-02-19 16:53:32
【问题描述】:
这是控制器 1:
@Controller
@RequestMapping("/clusters")
public class ClusterController {
@Autowired
private ClusterService clusterService;
@RequestMapping(method = RequestMethod.GET)
public String getAllClusters(Model model){
List<Cluster> clusters = this.clusterService.getAllClusters();
model.addAttribute("clusters", clusters);
return "clusters";
}
@RequestMapping(value = "/clusterInfo", method = RequestMethod.GET)
public String getCluster(@RequestParam("id") Integer id, Model model){
Cluster cluster = this.clusterService.findClusterById(id);
model.addAttribute("cluster", cluster);
return "testcluster";
}
控制器 2:
@Controller
@RequestMapping("/requirements")
public class RequirementController {
@RequestMapping("/")
public String getRequirements(){
return "requirements";
}
}
首先我看到所有的集群。之后,我可以单击站点上的按钮来查看单个集群(来自控制器 1 的方法 2)。
当我看到一个单独的集群时,我想点击一个按钮来查看链接到该集群的需求。其方法在 Controller 2 中。
从控制器 1 到 2 时,我希望有以下 url 路径。
http://localhost:8080/clusters
http://localhost:8080/clusters/clusterInfo?id=1
http://localhost:8080/clusters/clusterInfo?id=1/requirements
这是我用来从 url 2 转到 3 的按钮。 更多
它不起作用并给我一个错误。我的问题是,如何使用指定的 url 路径从控制器 1 转到控制器 2 并检索控制器 2 中的 id=1?
这是我的第一个项目,所以我对 Spring Boot 和 Thymeleaf 了解不多。
【问题讨论】: