mybatis和layui结合使用时一种特殊的Statement returned more than one row, where no more than one was expected报错情况

1.设置association

        <association property="configCustomer" column="customer_id" select="com.hdax.mapper.ConfigCustomerMapper.queryById" javaType="ConfigCustomer" ></association>

2.数据库中表设计id允许0值,但这样就无法查到任何数据,也就是null

3.layui表格,定义方法获取封装对象的字段值

{field: 'theCustomerName', width: 220, title: '客户',},

4.pojo中定义方法

//用于页面展示的方法
    public String getTheCustomerName(){
        return configCustomer.getCustomer_name();
    }

5.此时运行时报错

Statement returned more than one row, where no more than one was expected

6.与ssm框架和mybatis无关系,报错原因是因为页面中调用到的方法:getTheCustomerName(),该方法无非空判断,当查询数据库返回null值的customer值时,调用该方法会报错如上,很奇怪为什么不是空指针异常,而且报错指向mybatis,我找了很久才找到报错原因

7.解决方式:第一种是添加非空判断,如果configCustomer为空则返回其他值,杜绝空指针的可能性;第二种是在页面中使用三元表达式,示例:

{field: 'customer_name', width: 220, title: '客户',
                    templet(d){
                        return d != null ? d.configCustomer != null ? d.configCustomer.customer_name : '无' : '无'
                    }},

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值