今天在頁面請求后台的時候遇到了一個問題,請求不到后台
頁面代碼
<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沒有帶后台要到請求的參數。