标签:
今天在页面请求后台的时候遇到了一个问题,请求不到后台
页面代码
<li>
<a href="javascript:void(0);" class="indicator statistics">
<span class="icon icon-statistics"></span>
统计中心
<span class="allow"></span>
</a>
<ul class="submenu">
<li><a href="${ctx }/views/material/BrandGrade_statistics_page">材价库统计</a></li>
<li><a href="${ctx }/views/material/BrandGrade_statistics_page">品牌库统计</a></li>
<li><a href="${ctx }/views/document/documentList/document_statistics_page">文档库统计</a></li>
<li><a href="${ctx }/views/material/BrandGrade_statistics_page">员工贡献榜</a></li>
</ul>
</li>
后台代码
/**
* 文档库页面
*/
@RequestMapping(value = "/document_statistics_page", produces = { WebConstant.WEB_CHARSET })
public String document_statistics_page(@RequestParam("isprivatedoc") String isprivatedoc,
HttpServletRequest request,HttpServletResponse response,Model model) throws Exception {
List<Document> getSourceList = documentListService.getSource();
List<Document> getCategoryList = documentListService.getCategory();//一级分类
Map<String, List<Map<String, String>>> thirdcategoryList = Maps.newConcurrentMap();
if (null != getCategoryList && !getCategoryList.isEmpty()) {
List<Document> getSubCategoryList = documentListService.getSubCategory();//二级级分类
for (Document category : getCategoryList) {
List<Map<String, String>> nodeList = new ArrayList();
String id = category.getId()+"";
for (Document category2 : getSubCategoryList) {
if(category2.getCategoryid()!=null&&id.equals(category2.getCategoryid())){
Map<String, String> subMap = new HashMap<String,String>();
subMap.put("id", category2.getSubcategoryid());
subMap.put("category", category2.getCategoryName());
nodeList.add(subMap);
}
}
thirdcategoryList.put(id, nodeList);
}
}
model.addAttribute("getCategoryList", getCategoryList);
model.addAttribute("thirdcategoryList", thirdcategoryList);
model.addAttribute("getSourceList", getSourceList);
return "/statistics/document_statistics1";
}
后来找到了是使用SpringMVC注解@RequestParam的问题:
使用SpringMVC注解@RequestParam(value="XXX",required=false)时需要注意的问题
@RequestParam(value = what required = true)
void test(int what){};
这个是传参 当他为false 时 使用这个注解可以不传这个参数 true时必须传
required默认值是true
原因是我在页面的 href没有带后台要到请求的参数。
@RequestParam(required = true),@RequestParam(required = true)
标签:
原文地址:http://www.cnblogs.com/heganlin/p/5748731.html