Mybatis传入String类型参数问题
Dao层接口如下:
String selectUserIdByOrderCode(String orderCode);
mybatis的xml代码:
<select id="selectUserIdByOrderCode" resultType="java.lang.String" parameterType="java.lang.String">
select
rd.user_id
from order_info oi
left join res_driver rd on oi.driver_id = rd.id
<where>
<if test="orderCode != null and orderCode != ">
and oi.order_code = #{orderCode}
</if>
</where>
</select>
一般我们都是按这样的方式来写的,对于其他类型是没错的,但是如果为String的话会抛下面的异常: There is no getter for property named ‘type ’ in ‘class java.lang.String’
因为MyBatis要求如果参数为String的话,不管接口方法的形参是什么,在Mapper.xml中引用时需要改变为_parameter才能识别
解决的办法是在接口参数加上mybatis中的@param注解
String selectUserIdByOrderCode(@Param("orderCode") String orderCode);
