I am trying to pass clusterId=1
as parameter from
<a href="http://192.168.11.134:8080/UniconnectConfigurationWeb/nodes?clusterId=1">
and get it into spring mvc controller through @PathParam("clusterId")Integer clusterId
. But I'm getting 404 error.
Guide me how to pass parameter through anchor tag and how to hit controller and get the parameter value. I am sharing my code below,
@RequestMapping(value = "/nodes?clusterId={clusterId}", method = RequestMethod.GET)
public ModelAndView nodes(@RequestParam("clusterId")Integer clusterId,HttpSession session, HttpServletRequest request) {
System.out.println(clusterId);
return dashboard;
}
}
<c:url var="myURL" value="http://192.168.11.134:8080/UniconnectConfigurationWeb/nodes">
<c:param name="clusterId" value="1"/>
</c:url>
答案 0 :(得分:1)
这里您使用clusterId作为请求参数,并从客户端传递到服务器端。但是在您的服务器端代码中,您在请求映射注释中使用?clusterId={clusterId}
,并且您尝试使用@RequestParam
注释接收该请求参数。这里@RequestParam
足以接收请求参数。所以,不需要使用这个?clusterId = {clusterId}`,这不是编写服务器端URL的正确方法。
它可以帮助您更好地理解@RequestParam vs @PathVariable