错误1
java.lang.NullPointerException
at com.utils.MybatisUtils.getSqlSession(MybatisUtils.java:34)
at com.dao.UserDaoTest.test(UserDaoTest.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at s
这里一直空指针异常,原因是重复定义了sqlSessionFactory对象,把下面的SqlSessionFactory删去即可,修改后:
错误2
在配置文件中路径一定是斜杠“/”!!!不是点!
错误3
在些delUser()方法时parameterType写错
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.dao.UserMapper.delUser
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
at org.apache.ibatis.binding.MapperProxy.lambda$cachedMapperMethod$0(MapperProxy.java:98)
修改后:
错误4
解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
这是因为生成的target文件中找不到配置文件UserMapper.xml
解决方法,在父项目和子项目的pom.xml的<properties>标签内都加上:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
添加完后一定记得刷新!!maven需要刷新才能生效!!!