跟进
鉴于必须在 JSP 中完成的新要求,即使下面原始答案中列出的 Spring 处理程序代码可以添加带有相关信息的 Model 属性,这里是如何做到这一点的。
类似的两种方式如下:
<!-- Use the parameter Map -->
<c:if test="${empty param}">
<!-- no query parameters given -->
</c:if>
<!-- Use the request object -->
<c:if test="${pageContext.request.queryString == null}">
<!-- no query parameters given -->
</c:if>
原答案
你标记了spring-mvc,所以这意味着你有这样的东西(如果你发布它会很好):
@Controller
public class ProductController {
@RequestMapping("/Product/UniqueId")
public String uniqueId(Model model,
@RequestParam(path="code" , required=false) String code,
@RequestParam(path="sig" , required=false) String sig,
@RequestParam(path="pod" , required=false) String pod,
@RequestParam(path="circle" , required=false) String circle,
@RequestParam(path="location", required=false) String location,
@RequestParam(path="color" , required=false) String color) {
// code here
}
}
这里有两种检查“无查询参数”的方法:
// Get all parameters in a Map
public String uniqueId(Model model,
...,
@RequestParam Map<String, String> allParams) {
if (allParams.isEmpty()) {
// no query parameters given
}
// code here
}
// Use the request object
public String uniqueId(Model model,
...,
HttpServletRequest request) {
if (request.getQueryString() == null) {
// no query parameters given
}
// code here
}
您可能想查看此链接以了解 Spring 可以为您提供的所有各种类型的参数:
http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-arguments