目錄
1、傳入類型
當入參爲 string類型時 (包括java.lang.String.),也包括入參爲 Integer類型時
我們使用#{xxx}引入參數,會拋異常There is no getter for property named 'XXX' in 'class java.lang.String'
<select id="queryList" resultType="com.soft.back.model.OutdevFactory"
parameterType="java.lang.String">
select
<include refid="Base_Column_List"/>
from op_outdev_factory
<where>
<if test="factoryName != null">
and name like concat('%',#{factoryName},'%')
</if>
</where>
</select>
2、解決方案
方案一:把#{xxx}修改爲 #{_parameter} 即可
<select id="queryList" resultType="com.soft.back.model.OutdevFactory"
parameterType="java.lang.String">
select
<include refid="Base_Column_List"/>
from op_outdev_factory
<where>
<if test="_parameter != null">
and name like concat('%',#{_parameter},'%')
</if>
</where>
</select>
方案二:可以在方法中提前定義
/**
* 查詢廠家列表
* @param factoryName
* @return
*/
List<OutdevFactory> getFactoryList(@Param("factoryName") String factoryName);
<select id="queryList" resultType="com.soft.back.model.OutdevFactory"
parameterType="java.lang.String">
select
<include refid="Base_Column_List"/>
from op_outdev_factory
<where>
<if test="factoryName!= null">
and name like concat('%',#{factoryName},'%')
</if>
</where>
</select>
3、出現原因
Mybatis默認採用OGNL解析參數,所以會自動採用對象樹的形式取 string.xxx 值,如果沒在在方法中定義,則會拋異常報錯
4、注意事項
其他mybatis的版本不知道有沒有這個問題,暫時不知道會不會出現這個問題。