当前位置:首页 > mybatis传入参数为string报错

mybatis传入参数为string报错

点击次数:1317  更新日期:2018-09-26

mybatis传入参数为string时,如果这样写

<update id="exec" parameterType="string">
    ${sql}
</update>

会报错

org.mybatis.spring.MyBatisSystemException: 
nested exception is org.apache.ibatis.reflection.ReflectionException: 
There is no getter for property named 'sql' in 'class java.lang.String'

正确写法为

<update id="exec" parameterType="string">
    ${_parameter}
    </update>

无论参数名是啥,都要改成"_parameter"