2014年2月3日 星期一

mybatis - 使用parameterType="String"時出現There is no getter for property named....

參考:Mybatis-There is no getter for property named 'XXX' in 'class java.lang.String'解决办法


問題:
原先mapper.xml如下
 
  
     CREATE TABLE IF NOT EXISTS  ${table}
 (
    SERIALID varchar(20) NOT NULL,
    ACTIONID varchar(10) NOT NULL
 );
    


但執行時會出現以下錯誤:

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

(上述方式是因為測試需要在runtime時期建立不同的table,因此為了方便測試才使用這種接字串方式組Query帶值<使用${param}>)

出現:

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


解法:
將 ${table}修改為${_parameter}就可以了,更改後如下:

 
  
     CREATE TABLE IF NOT EXISTS  ${_parameter}
 (
    SERIALID varchar(20) NOT NULL,
    ACTIONID varchar(10) NOT NULL
 );
    

沒有留言:

張貼留言