IllegalStateException
java.lang.IllegalStateException: Optional long parameter 'id' is present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
1 angularJS
controller代碼
// 根據id查詢列表
this.findByParentId=function(parentId){
return $http.get('../itemCat/findByParentId.do?parentId='+parentId);
}
service代碼
//搜索
$scope.findByParentId=function(parentId){
alert(parentId);
itemCatService.findByParentId(parentId).success(
function(response){
$scope.list=response;
}
);
}
2 web
service代碼
//根據id查詢列表數據
public List<TbItemCat> findByParentId(Long id);
serviceImpl代碼
@Override
public List<TbItemCat> findByParentId(Long id) {
System.out.println(id);
TbItemCatExample example = new TbItemCatExample();
Criteria criteria = example.createCriteria();
criteria.andParentIdEqualTo(id);
return itemCatMapper.selectByExample(example);
}
controller代碼
// 根據id查詢列表
@RequestMapping("/findByParentId")
public List<TbItemCat> findByParentId(long id) {
System.out.println(parentId);
return itemCatService.findByParentId(parentId);
}
檢查發現後端controller參數是long,改成包裝類Long,發生如下報警
java.lang.RuntimeException: Value for parentId cannot be null
將id輸出運行,輸出爲null,檢查參數,發現參數名錯誤……..與get請求提交不一致