源代码片段:
1 <insert id="addAdminAction" parameterType="x.x.x.RoleVo"> 2 <selectKey keyProperty="idRole, createdDate" resultType="x.x.x.RoleVo" order="BEFORE"> 3 select getid() idRole, to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') createdDate from dual 4 </selectKey> 5 <!-- insert sql--> 6 </insert>
报错内容:
1 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ' createdDate' in 'class x.x.x.RoleVo'
原因:当keyProperty有多个目标列时,列关键字之间用逗号","分隔,并且不应有多余空格(即keyProperty="idRole, createdDate"间不应该有空格)。
正确代码片段:
1 <insert id="addAdminAction" parameterType="x.x.x.RoleVo"> 2 <selectKey keyProperty="idRole,createdDate" resultType="x.x.x.RoleVo" order="BEFORE"> 3 select getid() idRole, to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') createdDate from dual 4 </selectKey> 5 <!-- insert sql--> 6 </insert>
一个空格引起的错误,个人觉得还是挺有意思的