Mybatis selectKey標簽的keyProperty屬性報錯,關鍵字間隔不能有空格


源代碼片段:

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>

 

一個空格引起的錯誤,個人覺得還是挺有意思的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM