问题:使用mybatis对象插入参数的时候,数据插入成功,但是控制台报错
org.apache.ibatis.binding.BindingException: Mapper method 'com.learning.mybatis.mapper.ParameterMapper.insertUser attempted to return null from a method with a primitive return type (int).
修改接口和测试类都没有解决问题:
@Test
public void testInsertUser() {
SqlSession sqlSession = SqlSessionUtils.getSqlSession();
//获取mapper接口对象
ParameterMapper mapper = sqlSession.getMapper(ParameterMapper.class);
int result = mapper.insertUser(new User(null, "阿草", "123456", 18, "男", "123@qq.com"));
System.out.println("result = " + result);
}
/**
* 添加用户信息
* @param user
* @return
*/
int insertUser(User user);
解决方法: 写insert语句的时候,mybatis标签顺手写成了select
,修改成insert
即可
问题解决:
总结
学习的时候应该投入一点,不能边聊天边学习,否则容易出这种低级错误