Mybatis報錯:org.apache.ibatis.exceptions.PersistenceException:
阿新 • • 發佈:2018-12-11
mybatis框架,在進行測試類測試時候一直報錯,如下: org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'roleCode ’ of ‘class cn.smbms.entity.Role’ with value ‘SMBMS_EMPLOYEE’ Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'roleCode ’ in ‘class cn.smbms.entity.Role’
The error may exist in cn/smbms/dao/user/UserMapper.xml
The error may involve cn.smbms.dao.user.UserMapper.getUserListByRoleId-Inline
The error occurred while setting parameters
SQL: select u.*,r.id as r_id,r.roleCode,r.roleName from smbms_user u ,smbms_role r where u.userRole=? and u.userRole=r.id
Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'roleCode ’ of ‘class cn.smbms.entity.Role’ with value ‘SMBMS_EMPLOYEE’ Cause: org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'roleCode ’ in ‘class cn.smbms.entity.Role’
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) 前前後後找了好幾表程式碼也沒錯呀,報的是UserMapper.xml中可能錯了,說roleCode沒找到,無法賦值,在裡面找了好幾遍,也沒發信錯誤呀。 這是UserMapper.xml裡面的錯誤的sql <resultMap type="user" id="userRoleResult"> <id property="id" column="id"/> <result property="userCode" column="userCode"/> <result property="userName" column="userName"/> <result property="userRole" column="userRole"/> <association property="role" javaType="Role"> <id property="id" column="r_id"/> <result property="roleCode " column="roleCode"/> <result property="roleName" column="roleName"/> </association> </resultMap> <select id="getUserListByRoleId" resultMap="userRoleResult" parameterType="Integer"> select u.*,r.id as r_id,r.roleCode,r.roleName from smbms_user u ,smbms_role r where u.userRole=#{userRole} and u.userRole=r.id </select> 仔仔細細看了好幾遍才發現原來是property="roleCode " 中多了個空格,把空格去掉,property="roleCode",就沒問題了,就是一個空格,不小心還真不容易發現,寫程式碼一定認真,馬虎不得呀。