Optional long parameter 'id' is present but cannot be translated into a null value due to being decl
今天在使用前端向后端传递数据的时候发生了下面的问题
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、前端部分代码
向后端传递三个参数:每个目录下叶子节点的id--categoryId、每页显示的行数 PageSize 、当前页 CurrentPage
刷新页面:每当后端传递数据后进行刷新页面。
前提条件:必须是目录下的叶子节点
<div class="easyui-panel" title="Nested Panel" data-options="width:'100%',minHeight:500,noheader:true,border:false" style="padding:10px;">
<div class="easyui-layout" data-options="fit:true">
<div data-options="region:'west',split:false" style="width:250px;padding:5px">
<ul id="contentCategoryTree" class="easyui-tree" data-options="url:'/content/category/list',animate: true,method : 'GET'">
</ul>
</div>
<div data-options="region:'center'" style="padding:5px">
<table class="easyui-datagrid" id="contentList" data-options="toolbar:contentListToolbar,singleSelect:false,collapsible:true,pagination:true,method:'get',pageSize:20,url:'/content/query/list',queryParams:{categoryId:0}">
<thead>
<tr>
<th data-options="field:'id',width:30">ID</th>
<th data-options="field:'title',width:120">内容标题</th>
<th data-options="field:'subTitle',width:100">内容子标题</th>
<th data-options="field:'titleDesc',width:120">内容描述</th>
<th data-options="field:'url',width:60,align:'center',formatter:TAOTAO.formatUrl">内容连接</th>
<th data-options="field:'pic',width:50,align:'center',formatter:TAOTAO.formatUrl">图片</th>
<th data-options="field:'pic2',width:50,align:'center',formatter:TAOTAO.formatUrl">图片2</th>
<th data-options="field:'created',width:130,align:'center',formatter:TAOTAO.formatDateTime">创建日期</th>
<th data-options="field:'updated',width:130,align:'center',formatter:TAOTAO.formatDateTime">更新日期</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(function(){
var tree = $("#contentCategoryTree");
var datagrid = $("#contentList");
tree.tree({
onClick : function(node){
if(tree.tree("isLeaf",node.target)){
datagrid.datagrid('reload', {
categoryId :node.id
});
}
}
});
});
</script>
2、后端:、
添加注解ContController以及AutoWrited(不要忘记)
根据SpringMVC配置文件中dubbo引用ContentService服务进行查询信息。
参数,调用service层的方法
@RequestMapping("/content")
@Controller
public class ContentControllers {
// 注解注入
@Autowired
private ContentService contentService;
/**
*根据id查询列表
*@RequestParam(name="categoryId",defaultValue="0")
*/
@RequestMapping("/query/list")
@ResponseBody
public EasyUIDataResult getContentList(long categoryId,Integer page, Integer rows ){
System.out.println(categoryId);
EasyUIDataResult result = contentService.queryContentList(categoryId,page,rows);
System.out.println(result);
return result;
}
}
3、问题:
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.
4、解决:
出现这个的原因是因为,我在前端发送的参数是categoryId。但是我在第一次接收的参数中写成了id。导致了此次错误。望下次引以为戒。
上一篇: 记录一次掉坑过程
下一篇: 设计中的 Less 和 More
推荐阅读
-
Optional long parameter 'id' is present but cannot be translated into a null value due to being decl
-
Optional int parameter 'xx' is present but cannot be translated into a null value
-
Optional int parameter 'xx' is present but cannot be translated into a null value
-
Optional int parameter ‘productId‘ is present but cannot be translated into a null value
-
Optional int parameter ‘isApply‘ is present but cannot be translated into a null value已解决