自学遇到的问题,会不断更新
1.org.apache.ibatis.exceptions.PersistenceException: Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.insertUser
Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.insertUser
...
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for text.insertUser
解决办法:
查看text.insertUser名字中text是否和命名空间一直,namespace="text"
2.模糊查询书写不规范
Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%五$' at line 1
The error may exist in sqlmap/User.xml
The error may involve test.findUserByUsername-Inline
The error occurred while setting parameters
SQL: select * from user where username=%五$
Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%五$' at line 1
解决办法:查看sqlmap/User.xml文件中的findUserByUsername函数,修改模糊查询写法
分析:
在mybatis中,
ID查询固定书写模式:
select * from user where username like "%"#{value}"%" <!-- value 处可以随便写 -->
模糊查询固定书写模式:
select * from user where username like '%${value}%' <!-- 只能写 value -->
select * from user where username like "%"#{value}"%" <!-- value 处可以随便写 -->
3.Error building SqlSession.
The error may exist in com/itheima/mybatis/mapper/UserMapper.xml
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'User'. Cause: java.lang.ClassNotFoundException: Cannot find class: User
解决方法:查看com/itheima/mybatis/mapper/UserMapper.xml文件,所有User未找到都是路径不完整,补充完整即可
报错的书写:
<select id="findUserById" parameterType="Integer"resultType="User">
正确的书写(补充路径):找到你User.java文件的路径
<select id="findUserById" parameterType="Integer" resultType="com.itheima.mybatis.pojo.User">