Mybatis学习过程中的报错及解决

自学遇到的问题,会不断更新

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">



          

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值