当进行mybatis的xml配置时,插入的paramaterType=java.lang.String时,出现问题:There is no getter for property named 'phaseCode' in 'class java.lang.String'
xml中代码如下:
<select id="getVocabularyByPhaseCode" resultMap="vocabularyMap" parameterType="java.lang.String" > select * from vocabulary where word_id in ( select max(word_id) from vocabulary where audio_path !='' AND is_delete =0 and phase_code like "%${phaseCode}%" group by word ) limit 200 </select>
解决方法:
1) 在mapper.java中加入@param,代码如下:
List<Vocabulary> getVocabularyByPhaseCode(@Param( "phaseCode" ) String phaseCode);
xml中sql代码为:
select max(word_id) from vocabulary where audio_path !='' AND is_delete =0 and phase_code like "%${phaseCode}%" group by word
2) 把#{xxx}修改为 #{_parameter} 即可
select max(word_id) from vocabulary where audio_path !='' AND is_delete =0 and phase_code like "%${_parameter}%"
原因:Mybatis默认采用OGNL解析参数,所以会自动采用对象树的形式取 string.xxx 值,如果没在在方法中定义,则会抛异常报错。