at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:74)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
at com.sun.proxy.$Proxy17.getUserCount(Unknown Source)
at com.huawei.idp.composer.user.mgr.impl.ProcesserMgrImpl.getUserCount(ProcesserMgrImpl.java:24)
at com.huawei.idp.composer.user.mgr.impl.ProcesserMgrImplTest.testGetUserCount(ProcesserMgrImplTest.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
存储过程
DELIMITER $
CREATE PROCEDURE mybatis.ges_user_count(IN sex_id INT, OUT user_count INT)
BEGIN
IF sex_id=0 THEN
SELECT COUNT(*) FROM mybatis.p_user WHERE p_user.sex='女' INTO user_count;
ELSE
SELECT COUNT(*) FROM mybatis.p_user WHERE p_user.sex='男' INTO user_count;
END IF;
END
$
<?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.huawei.idp.composer.user.dao.ProcesserUserDao">
<select id="getUserCount" parameterMap="getUserCountMap" statementType="CALLABLE">
CALL mybatis.ges_user_count(?,?)
</select>
<parameterMap id="getUserCountMap" type="java.util.Map">
<parameter property="sexid" jdbcType="INTEGER" mode="IN"></parameter>
<parameter property="usercount" jdbcType="INTEGER" mode="OUT"></parameter>
</parameterMap>
</mapper>
package com.huawei.idp.composer.user.mgr.impl;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.huawei.idp.composer.user.dao.ProcesserUserDao;
import com.huawei.idp.composer.user.mgr.ProcesserUserMgr;
@Service
public class ProcesserMgrImpl implements ProcesserUserMgr {
@Resource(name="processerUserDao")
private ProcesserUserDao processerUserDao;
@Override
public int getUserCount(int sexId) {
Map<String, Integer> parameterMap = new HashMap<String, Integer>();
parameterMap.put("sexid", sexId);
parameterMap.put("usercount", -1);
processerUserDao.getUserCount(parameterMap);
Integer result = parameterMap.get("usercount");
return result;
}
}
package com.huawei.idp.composer.user.dao;
import java.util.Map;
public interface ProcesserUserDao {
public void getUserCount(Map<String, Integer> parameterMap);
// int sexId, int
}
最终的错误原因是因为把ProcesserUserDao 的返回值写成int了,存储过程的返回值已经返回给Map中的参数了,接口没有返回值。