1.没有在configuration.xml配置对应的sql配置文件

错误:

Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for ***Mapper.*** Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for ***Mapper.***
解决方法:

在configuration.xml配置文件中引用对应的sql配置文件

  1. <mappers>
  2. <mapper resource="esd/db/mapper/ResumeMapper.xml" />
  3. </mappers>

2.同一sql配置文件中id重复

错误:

Cause: org.apache.ibatis.builder.BuilderException: Error
parsing SQL Mapper Configuration. Cause: java.lang.RuntimeException:
Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException:
Mapped Statements collection already
contains value for GeographyMapper.getByCode
两个sql语句的id重复了,就会报这个错.

  1. <!-- 按code码得到一个对象-->
  2. <select id="getByCode" resultType="Geography"
  3. parameterType="java.lang.String">
  4. select * from Geography where code = ${code}
  5. </select>
  6. <!-- 按地名getByName得到一个对象-->
  7. <select id="getByCode" resultType="Geography"
  8. parameterType="java.lang.String">
  9. select * from Geography where fullName = ${fullName}
  10. </select>

解决方法:

修改其中的一个id就ok了.
3.mapper配置文件中为bean类配置的属性没有在对应的bean类中找到对应的字段

错误:

Error updating database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'education' in 'class esd.bean.Personal'
Cause: org.apache.ibatis.reflection.ReflectionException: There is no
getter for property named 'education' in 'class esd.bean.Personal'

  1. <!-- 这个属性是多余的,在对应的bean类中没有对应的字段,删除后OK -->
  2. <if test="education != null and education != ''">
  3. education = #{education},
  4. </if>

解决方法:

在mapper配置文件中删除多配置的属性/或则在自己的bean类中补全该字段

4.<if>标签中不支持 && 符号

错误:

The entity name must immediately follow the '&' in the entity reference

解析不了 && 是什么东东

  1. <update id="update" parameterType="Geography">
  2. update Geography
  3. <trim prefix="set" suffixOverrides=",">
  4. <if test="code != null && code !=''">
  5. code=#{code},
  6. </if>
  7. <if test="name != null && name != ''">
  8. name=#{name},
  9. </if>
  10. </trim>
  11. where id= #{id}
  12. </update>

解决方法:使用正确的语法咯,别用&&,用and

  1. <!-- update -->
  2. <update id="update" parameterType="Geography">
  3. update Geography
  4. <trim prefix="set" suffixOverrides=",">
  5. <if test="code != null and code !=''">
  6. code=#{code},
  7. </if>
  8. <if test="name != null and name != ''">
  9. name=#{name},
  10. </if>
  11. </trim>
  12. where id= #{id}
  13. </update>

5.返回结果类型写错

由于我的项目配置原因, debug 输出信息中没有报错, 但是项目就是启动不起来, 所以没能截到错误信息提示, 以后遇到会补上

具体说就是: 如果自定义了返回的结果集, 返回的类型一定要是resultMap类型,(下面是错误示例) 如下

  1. <!-- 查询Area 地名 -->
  2. <resultMap id="ResultArea" type="Area">
  3. <id column="a_code" property="code" />
  4. <result column="a_name" property="name" />
  5. <result column="a_pyName" property="pyName" />
  6. <result column="a_abbr" property="abbr" />
  7. <result column="a_mark" property="mark" />
  8. </resultMap>
  9. <!-- 查询Parameter 地名 -->
  10. <resultMap id="ResultParameter" type="Parameter">
  11. <id column="p_id" property="id" />
  12. <result column="p_name" property="name" />
  13. <result column="p_value" property="value" />
  14. <result column="p_type" property="type" />
  15. <result column="p_mark" property="mark" />
  16. <association property="area" javaType="Parameter" resultMap="ResultArea" />
  17. </resultMap>
  18. <!-- get by id -->
  19. <select id="getById" resultType="ResultParameter" parameterType="int">
  20. select p.id as p_id, p.name as p_name, p.value as p_value, p.type as p_type, p.mark as p_mark,
  21. a.code as a_code, a.name as a_name, a.pyname as a_pyName, a.abbr as a_abbr, a.mark as a_mark
  22. from parameter as p, area as a
  23. where p.acode = a.code and id = #{id}
  24. </select>

常用在表连接查询中.

如上例中, 我定义了'ResultParameter'的结果集,  那么下面表连接查询的时候,如果返回的是表连接查询结果, 那么一定要使用

  1. <resultMap id="ResultMenu" type="com.esd.hesf.model.Menu">
  2. <id column="id" property="id" jdbcType="CHAR" />
  3. <result column="text" property="text" jdbcType="VARCHAR" />
  4. <result column="iconcls" property="iconcls" jdbcType="VARCHAR" />
  5. <association property="permissionType" javaType="com.esd.hesf.model.PermissionType" resultMap="ResultPermissionType"/>
  6. <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  7. </resultMap>

在<resultMap 处画红线,   原因是: 里面的<association />标签, 一定要放在这组标签最下面.  如下:

  1. <resultMap id="ResultMenu" type="com.esd.hesf.model.Menu">
  2. <id column="id" property="id" jdbcType="CHAR" />
  3. <result column="text" property="text" jdbcType="VARCHAR" />
  4. <result column="iconcls" property="iconcls" jdbcType="VARCHAR" />
  5. <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  6. <association property="permissionType" javaType="com.esd.hesf.model.PermissionType" resultMap="ResultPermissionType"/>
  7. </resultMap>

7.多写了if判断

错误:

org.apache.ibatis.reflection.ReflectionException:
There is no getter for property named 'year' in 'class java.lang.String'

下面是代码:

dao层方法

  1. /**
  2. * 查询审核报表情况--按公司类型查
  3. * @return
  4. */
  5. List<ReportViewModel> retrieveReportByCompanyType(String year);

mapper配置文件

  1. <!-- retrieve report statistics by company type -->
  2. <select id="retrieveReportByCompanyType" parameterType="java.lang.String" resultMap="ReportViewModel">
  3. select
  4. <include refid="report_column_list"/>
  5. from audit_company_view
  6. <where>
  7. <if test="year != null and year != ''">
  8. au_year = #{year,jdbcType=CHAR}
  9. </if>
  10. </where>
  11. group by t_id
  12. </select>

一般这个错是指参数parameterType类型的字段 没有get, set方法, 我只是传个String类型的参数, so 刚遇到这个问题的时候, 有点摸不着头脑, 怎么会报这个错呢? 原来问题出现在配置文件中:

  1. <if test="year != null and year != ''">

mybatis自动将if判断中的字段默认为传进来的parameterType类型的字段了... so....只要将这个if判断去掉即可.

  1. <!-- retrieve report statistics by company type -->
  2. <select id="retrieveReportByCompanyType" parameterType="java.lang.String" resultMap="ReportViewModel">
  3. select
  4. <include refid="report_column_list"/>
  5. from audit_company_view
  6. <where>
  7. au_year = #{year,jdbcType=CHAR}
  8. </where>
  9. group by t_id
  10. </select>

那问题出来了, 我怎么判断传进来的单个字符串是否为空值呢? 这是否是mybatis的一个小bug呢?  答案尚在查找中, 有了会第一时间贴上来的.

mybatis--常见的错误的更多相关文章

  1. Mybatis常见配置错误总结

    Mybatis常见配置错误总结 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionF ...

  2. mybatis常见问题和错误

    1. jdbc java type 映射关系 1) mysql的text 在mybatis中使用varchar类型 2. mybatis常见的错误 3.There is no getter for p ...

  3. mybatis学习笔记--常见的错误

    原文来自:<mybatis学习笔记--常见的错误> 昨天刚学了下mybatis,用的是3.2.2的版本,在使用过程中遇到了些小问题,现总结如下,会不断更新. 1.没有在configurat ...

  4. 新手学习Python时常见的错误

    最近学习Python,现在把一些常见的错误总结如下: 1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 "Synta ...

  5. Android自动化压力测试之Monkey Test Android常见的错误类型及黑白名单的使用方法(四)

    Android常见的错误类型有两种 1.ANR类型 1)在5秒内没有响应输入的事件(例如,按键按下,屏幕触摸) 2)BroadcastReceiver在10秒内没有执行完毕 2.Crash类型 1)异 ...

  6. php常见细节错误

    PHP编程中10个最常见的错误 PHP是一种非常流行的开源服务器端脚本语言,你在万维网看到的大多数网站都是使用php开发的.本篇经将为大家介绍PHP开发中10个最常见的问题,希望能够对朋友有所帮助. ...

  7. TCP/IP 某些最常见的错误原因码 (errno)列表

    对于在基于 UNIX 的环境中的 TCP/IP 用户,下表列出了某些最常见的错误原因码 (errno).它不是完整的错误列表.可以在文件 /usr/include/sys/errno.h 中找到 Er ...

  8. VC6.0常见编译错误提示

    原文:http://c.biancheng.net/cpp/html/746.html 1) error C2001: newline in constant 编号:C2001 直译:在常量中出现了换 ...

  9. HTML5几种常见的错误写法

    本文介绍了HTML5常见的6种错误写法,包括:1.不要使用section作为div的替代品 2.只在需要的时候使用header和hgroup 3.不要把所有列表式的链接放在nav里 4.figure元 ...

  10. 初学JSP+Servlet常见的错误

    web编程中常见的错误: 一.404(要访问的资源没有找到) 1.web程序有没有部署(将项目到tomcat中) 2.url有没有写错(包括大小写,包括项目有没有重命名) 3.有没有将jsp/html ...

随机推荐

  1. nginx之fastcgi

    fastcgi的应用程序就是一个while循环在,不停的accept,如果收到相应的服务请求则负责服务并将结果返回. 在fastcgi的进程环境中,标准输入与标准输出已经被重定向到了监听的socket ...

  2. HDU1114--Piggy-Bank(完全背包变形)

    Piggy-Bank   Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. VNC轻松连接远程Linux桌面

    VNC连接Linux桌面,要想连接Linux远程桌面,按照下面的步骤,非常简单.快速,Linux配置VNC(以RedHat.CentOS.Fedora系列为例). 工具/原料 Linux平台安装VNC ...

  4. POJ2096 概率dp 入门

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=118282#problem/B 挺好的一个题目: 不过刚开始嘛,看别人题解长知识.这个人写 ...

  5. XML 从基础到精通

    1.简介 XML(可扩展标记语言)语言是一种数据交换标准,用于存储数据:关键词是标记: XML具有以下优点: (1) 方便的穿过防火墙,在不同的操作系统之间通信,跨语言,跨平台.数据共享非常方便.(J ...

  6. 转: OGG Checkpoint 详解

    1. OGG Checkpoint 详解 定位中断的位置,下次启动从中断的位置开始恢复. 1.target 端配置: 2.一条记录对应一个replicat 一. Extract Checkpoints ...

  7. 第2课 Linux操作系统简介

    1. Linux操作系统的构成 (1)内核(kernel) ①操作系统的核心,负责管理系统的进程.内存.设备驱动程序.文件和网络系统. ②控制系统和硬件之间的相互通信. ③决定着系统的性能和稳定性. ...

  8. sql server 日期转换函数 convert()

    --内容来自:http://hi.baidu.com/muqingz/item/8fb7b3ca8a485b0cac092f7b Select CONVERT(varchar(100), GETDAT ...

  9. zencart的modules下数据库操作templates排版和common首页引用

    把这个学会,zencart的数据库操作,以及各种函数的调用基本会了 这个东西非常有用,你需要认真看一下,不要闲代码多. 如何在数据库中调出自己想要的产品,让它显示在首页. 据我本人不科学的理解,在in ...

  10. Chapter 1 First Sight——7

    Eventually we made it to Charlie's. 最终我们到了查理斯的家. He still lived in the small,two-bedroom house that ...