使用myBatis调用存储过程的返回值,提示错误信息:

org.apache.ibatis.binding.BindingException: Mapper method 'com.xxxx.other.dao.MyDao.getNo attempted to return null from a method with a primitive return type (int).

先查mysql监控语句,发现存储过程调用正常,也得到了返回值,继续查

对应的文件

存储过程:

CREATE PROCEDURE `Get_Table_Flow_No`(IN `输入表名` VARCHAR(100), IN `待取数` INT, OUT `输出要取的最大流水号` INT)
BEGIN
DECLARE `willRetNo` INT; SET `输出要取的最大流水号` = 0 ; SELECT 字段_已取最大流水号 INTO `willRetNo` FROM 流水号保存表 WHERE 字段_表名=`输入表名` for UPDATE; IF `willRetNo` IS NULL THEN
SET `willRetNo` = `待取数` ;
INSERT INTO `流水号保存表`
(字段_表名,字段_已取最大流水号,字段_上次获取时间)
VALUES (`输入表名`, `willRetNo`, NOW());
ELSE
SET `willRetNo` = `willRetNo` + `待取数` ; UPDATE `流水号保存表`
SET 字段_已取最大流水号 = `willRetNo`
, 字段_上次获取时间 = NOW()
WHERE 字段_表名=`输入表名` ;
END IF; SET `输出要取的最大流水号` = `willRetNo`; END

  MyDao.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.xxxx.other.dao.MyDao">
<parameterMap type="java.util.Map" id = "FlowNoMap">
<parameter property="输入表名" mode="IN" jdbcType="VARCHAR"/>
<parameter property="待取数" mode="IN" jdbcType="INTEGER"/>
<parameter property="返回最大数值" mode="OUT" jdbcType="INTEGER"/>
</parameterMap> <select id="getFlowNo" parameterMap="FlowNoMap" statementType="CALLABLE">
<if test="_databaseId == 'mysql'">
call Get_Table_Flow_No(#{输入表名 ,jdbcType=VARCHAR,mode=IN},#{待取数,jdbcType=INTEGER,mode=IN},#{返回最大数值 ,jdbcType=INTEGER,mode=OUT});
</if>
<if test="_databaseId == 'sqlserver'"></if>
</select> </mapper>

  MyDao.java

package com.xxxx.other.dao;

import org.apache.ibatis.annotations.Param;
import org.springframework.dao.DataAccessException; import java.util.List;
import java.util.Map; public interface MyDao {
int getNo(Map<String, Object> parameterMap) throws DataAccessException;
}

错误信息出在:

org/apache/ibatis/binding/MapperMethod.java 方法 execute 中

    if (result == null && method.getReturnType().isPrimitive() && !method.returnsVoid()) {
throw new BindingException("Mapper method '" + command.getName()
+ " attempted to return null from a method with a primitive return type (" + method.getReturnType() + ").");
}

  因为result 为 null,所以抛出了异常,往上推,同文件中

else if (SqlCommandType.SELECT == command.getType()) {
if (method.returnsVoid() && method.hasResultHandler()) {
executeWithResultHandler(sqlSession, args);
result = null;
} else if (method.returnsMany()) {
result = executeForMany(sqlSession, args);
} else if (method.returnsMap()) {
result = executeForMap(sqlSession, args);
} else {
Object param = method.convertArgsToSqlCommandParam(args);
result = sqlSession.selectOne(command.getName(), param);
}
}

 调用的是最后一个条件:

Object param = method.convertArgsToSqlCommandParam(args);
result = sqlSession.selectOne(command.getName(), param);
调用的存储过程中,只是把值通过输出参数返回出来,没提供select语句,所以result为空,但param中有对"返回最大数值"取到值
再返回报错的地方,看到有验证条件: !method.returnsVoid() ,实际在myDao.xml中是没有返回的,查询 MyDao.java,
接口中有返回值: int getNo(Map<String, Object> parameterMap) throws DataAccessException;
把 int 调整为 void, 程序运行正常,通过 parameterMap 取到了最大数

Mapper method 'com.xxxx.other.dao.MyDao.getNo attempted to return null from a method with a primitive return type (int)的更多相关文章

  1. rg.apache.ibatis.binding.BindingException: Mapper method 'com.dao.Cameao.getOnlineDayRation attempted to return null from a method with a primitive return type (float)

    本文为博主原创,未经允许不得转载: 异常展示如下: org.apache.ibatis.binding.BindingException: Mapper method 'com.dao.Cameao. ...

  2. org.apache.ibatis.binding.BindingException: Mapper method 'attempted to return null from a method with a primitive return type (long).

    一.问题描述 今天发现测试环境报出来一个数据库相关的错误 org.apache.ibatis.binding.BindingException: Mapper method 'attempted to ...

  3. delete attempted to return null from a method with a primitive return type (int)

    今天被自己给蠢死了 今天在代码中遇到这个错误, 百度翻译一下:映射方法,从一org.system.mapper.child.chmorganizationexaminationmapper.delet ...

  4. attempted to return null from a method with a primitive return type (int).

    java接口文件 package com.cyb.ms.mapper; import org.apache.ibatis.annotations.Param; public interface Acc ...

  5. mybatis查询时使用基本数据类型接收报错-attempted to return null from a method with a primitive return type (int)

    一.问题由来 自己在查看日志时发现日志中打印了一行错误信息为: 组装已经放养的宠物数据异常--->Mapper method 'applets.user.mapper.xxxMapper.xxx ...

  6. mysql查询null异常:attempted to return null from a method with a primitive return type

    select sum(deposit_amount)from tb_commission_ib_day mysql查询时报异常: attempted to return null from a met ...

  7. Mapper method 'com.autoyol.mapper.trans.AccountLogMapper.getTotalIncomByMemNoLastest attempted to return null from a method with a primitive return type (int).解决方法

    1.打开日志输出,降低日志级别. <AppenderRef ref="console" level="trace"></AppenderRef ...

  8. spring3+structs2整合hibernate4时报org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void sy.dao.impl.UserDaoImpl.setSessionFactory(org.hibernate.SessionFactory);

    今天在spring3+structs2整合hibernate4时报如下错误,一直找不到原因: org.springframework.beans.factory.BeanCreationExcepti ...

  9. EF C# ToPagedList方法 The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must ……

    报错信息:The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' ...

随机推荐

  1. 组态DP主站与标准从站的步骤

    分为以下几个部分 第一:组态DP主站与标准从站 分为以下几个步骤 步骤1: 将标准从站ET200 ,ET200在硬件组态软件界面的最右边的PROFIBUS-DP界面里面, PROFIBUS-DP里面是 ...

  2. 分享Burp Suite遇到的各种坑

    1.性质问题 价格昂贵 专业版高达399美元/每年,免费版有功能限制:https://portswigger.net/buy/pro,构想中的工具应该是免费开源的. 破解版存在安全隐患 https:/ ...

  3. SystemVerilog基本语法总结(上)

    SystemVerilog基本语法总结(上) 在总结SV的语法之前,先分享一些关于SV的笔试题目,这样更显得具有针对性的总结. a. 验证中,代码覆盖率是指(衡量哪些设计代码在激活触发,而哪一些则一直 ...

  4. Oracle笔记--Sql语句

    1.SQL的三种类型语句: --1)DML(Data Manipulation Language)数据操纵语言 --2)DDL(Data Definition Language):数据定义语言 --3 ...

  5. javascript if else优化指南

    不管是平时在学习js中还是在项目书中写js代码,都避免不了一个问题就是有时候要做大量的分支判断,很多人的第一反应就是使用if else.无可厚非,if else早平时做分支判断的时候是非常好用的,但是 ...

  6. 配置uboot指定nfs挂载根文件系统

    背景: 文件系统的调试也建议在 网络中进行. 概念: NFS是Network File System的缩写及网络文件系统. 要功能是通过局域网络让不同的主机系统之间可以共享文件或目录. NFS系统和W ...

  7. 第二单元总结:基于synchronize锁的简单多线程设计

    单元统一的多线程设计策略 类的设计 电梯 每部电梯为一个线程. 电梯从调度器接收原子指令,知晓自己的状态(内部的人/服务的人.运行方向.所在楼层) 原子指令包括且仅包括: 向上走一层 / 向下走一层 ...

  8. 从ofo到乐视,变卖资产好过冬靠谱吗?

    今年年底,有很多人"被迫"离职.他们为了应对生活压力和找工作的不确定性,尝试在二手平台上卖出自己的奢侈品或心爱之物,以期度过潜在的难关.而对于很多企业来说,这个冬天也非常冷.依靠常 ...

  9. Day6-T4

    原题目 Describe:差分约束模板题吧...LG上竟然是省选+ code: #include<bits/stdc++.h> #define INF 214748364 using na ...

  10. Day6-T1

    原题目 Describe:模拟大水题 code: #include<bits/stdc++.h> #define INF 214748364 #define eps 1e-9 #defin ...