### Error querying database.  Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'sex' from result set.  Cause: java.lang.IllegalArgumentException: No enum constant chapter2.po.SexEnum.1
### The error may exist in chapter2/mapper/UserMapper.xml
### The error may involve chapter2.mapper.UserMapper.getUser
### The error occurred while handling results
### SQL: select * from t_user    WHERE id=?
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'sex' from result set.  Cause: java.lang.IllegalArgumentException: No enum constant chapter2.po.SexEnum.1
DEBUG 2019-04-30 22:38:55,672 org.apache.ibatis.transaction.jdbc.JdbcTransaction: Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.Connection@271053e1]
DEBUG 2019-04-30 22:38:55,672 org.apache.ibatis.transaction.jdbc.JdbcTransaction: Closing JDBC Connection [com.mysql.jdbc.Connection@271053e1]
DEBUG 2019-04-30 22:38:55,673 org.apache.ibatis.datasource.pooled.PooledDataSource: Returned connection 655381473 to pool.

解决方案 »

  1.   

    mapper配置
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper 
    PUBLIC "-//mybatis.org//DTD mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    <mapper namespace="chapter2.mapper.UserMapper">
    <resultMap type="chapter2.po.User" id="userMap">
    <id property="id" column="id" javaType="long" jdbcType="BIGINT"/>
    <result property="userName" column="user_name"/>
    <result property="cnname" column="cnname"/>
    <!-- 数据库多个字段确定sex的属性 -->
    <result property="sex" column="sex_name" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> 
    <!--<result property="sex" column="sex" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>-->
    <result property="mobile" column="mobile"/>
    <result property="email" column="email"/>
    <result property="note" column="note"/>
    <result property="birthday" column="birthday"/>
    </resultMap>
    <insert id="insertUser" parameterType="chapter2.po.User">
    insert into t_user(user_name,cnname,birthday,sex,sex_name,email,mobile,note)
    values(#{userName},#{cnname},#{birthday},
    #{sex ,typeHandler=org.apache.ibatis.type.EnumOrdinalTypeHandler},
    #{sex ,typeHandler=org.apache.ibatis.type.EnumTypeHandler},
    #{email},#{mobile},#{note}) 
    </insert> <select id="getUser" parameterType="long" resultMap="userMap">
    select * from t_user
    <where>
    id=#{id}
    </where>
    </select>
    </mapper>
      

  2.   

    <result property="sex" column="sex_name" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/> 
    <!--<result property="sex" column="sex" typeHandler="org.apache.ibatis.type.EnumOrdinalTypeHandler"/>-->上面的注释掉用下面handler可以运行很奇怪
      

  3.   

    结果集映射的不是枚举的value,或许可以试试自定义枚举 。
    参照:https://www.cnblogs.com/jeffen/p/6380724.html