【发布时间】:2022-01-10 22:48:16
【问题描述】:
我是 Java web 的新手,我在 Stack Overflow 中尝试了很多方法来解决问题,但都失败了。你能帮帮我吗?
我代码中的接口是:
public List<Answer> selectAnswerByUser(@Param("user") User user, @Param("id") Integer id);
Answer 和 User 是我定义的两个类。
映射器是:
<select id="selectAnswerByUser" parameterType="java.util.Map" resultType="Answer">
select * from answer where exercise_id=#{id} and user_email='#{user.email}'
</select>
其中 email 是 Class User 的一个变量。
它会抛出:
nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='user.email', mode=IN, javaType=class java.lang.Object, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}.
Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property.
Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property.
Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
我不知道这个异常。
【问题讨论】:
-
去掉单引号。 MyBatis 将
#{}替换为java.sql.PreparedStatement的占位符?,但是,如果占位符用单引号括起来,驱动程序会将其识别为字符串文字。
标签: java spring-boot mybatis