一些Mybatis的知识点&易错点总结

1、映射文件配置容易出错

在映射文件中,我们习惯性在sql语句后面添加';'。
结果是报了一堆错误:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map com.doing.pojo.User
### Cause: org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map com.doing.pojo.User

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ...

你能从下面的配置中找到哪些错误?


总共有三处错误:

  1. 建议使用parameterType,而不是使用"parameterMap"
  2. 不使用$进行绑定数据,而是使用#{}
  3. sql语句后面不要以";"结尾

正在更新中,如果有一起学习的小伙伴欢迎在评论区留言🥰

posted @ 2024-01-12 16:15  news_one  阅读(19)  评论(0编辑  收藏  举报