[英]Get Query String Values in Spring MVC Controller
I have a referrer URL like this: 我有一个像这样的推荐人网址:
http://myUrl.com?page=thisPage&gotoUrl=https://yahoo.com?gotoPage http://myUrl.com?page=thisPage&gotoUrl=https://yahoo.com?gotoPage
How do I get the Values of "page" and "gotoUrl" in my Spring Controller? 如何在Spring Controller中获取“page”和“gotoUrl”的值?
I want to store these values as variables, so I can reuse them later. 我想将这些值存储为变量,以便稍后重用它们。
In SpringMVC you can specify values from the query string be parsed and passed in as method parameters with the @RequestParam annotation. 在SpringMVC中,您可以使用@RequestParam注释指定查询字符串中的值,并将其作为方法参数传入。
public ModelAndView getPage(
@RequestParam(value="page", required=false) String page,
@RequestParam(value="gotoUrl", required = false) String gotoUrl) {
}
You can use the getParameter() method from the HttpServletRequest interface. 您可以使用HttpServletRequest接口中的getParameter()方法。
For example; 例如;
public void getMeThoseParams(HttpServletRequest request){
String page = request.getParameter("page");
String goToURL = request.getParameter("gotoUrl");
}
Get the QueryString
in Spring MVC Controller 在Spring MVC Controller中获取
QueryString
This is Liferay portal specific solution, and it works. 这是Liferay门户特定的解决方案,它的工作原理。
Query String Example: ?reportTypeId=1&reportSeqNo=391
查询字符串示例:
?reportTypeId=1&reportSeqNo=391
In order to get the value of reportSeqNo
in Liferay Portal, we need to get the Original Servlet Request. 为了在Liferay Portal中获取
reportSeqNo
的值,我们需要获取原始Servlet请求。
String reportSeq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest)).getParameter("reportSeqNo");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.