其他分享
首页 > 其他分享> > Mybatis中报错:attempted to return null from a method with a primitive return type (int)

Mybatis中报错:attempted to return null from a method with a primitive return type (int)

作者:互联网

发生缘由

环境

问题及补救

问题描述

其他文件就不在这里赘述了,有User类,自己抽取的SqlSessionUtils类,以及配置文件等等。

UserMapper.java

    /**
     * 插入一条用户信息
     */
    int insertUser(User user);

UserMapper.xml

    <!--User insertUser(User user);null,'张三','123456',24,'男', '12345@qq.com'-->
    <select id="insertUser" resultType="user">
        insert into t_user values(null, #{username}, #{password}, #{age}, #{sex}, #{email});
    </select>

创建测试类运行:

    @Test
    public void testInsertUser() {
        SqlSession sqlSession = SqlSessionUtils.getSqlSession();
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
​
        int result = mapper.insertUser(new User(null, "张三", "243", 34, "男", "234@qq"));
        System.out.println(result);
    }

结果报错:

org.apache.ibatis.binding.BindingException: Mapper method 'com.linxuan.mybatis.mapper.UserMapper.insertUser attempted to return null from a method with a primitive return type (int).

解决方案

标签:primitive,return,int,UserMapper,insertUser,报错,User,null
来源: https://www.cnblogs.com/linxuannihao/p/16208139.html