最近写sql(mybatis),用了下面的代码,如下图所示:
<select id="findById" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
*
from ot_user
where
<if test="userId == null" >
user_id is null
</if>
<if test="userId != null" >
user_id = #{userId,jdbcType=VARCHAR}
</if>
</select>
然后报了个错误,异常信息如下:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'userId' in 'class java.lang.String'
错误信息很明显,后来搜了下,要改成下面的方式(使用_parameter代替传入的参数)
<select id="findById" resultMap="BaseResultMap" parameterType="java.lang.String" >
select
*
from ot_user
where
<if test="_parameter == null" >
user_id is null
</if>
<if test="_parameter != null" >
user_id = #{userId,jdbcType=VARCHAR}
</if>
</select>