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。导致了此次错误。望下次引以为戒。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值