I am a new starter of Java web and I have tried many ways in Stack Overflow to solve the problem but failed. Could you help me?
The interface in my code is:
public List<Answer> selectAnswerByUser(@Param("user") User user, @Param("id") Integer id);
where Answer
and User
are two classes I have defined.
The Mapper is:
<select id="selectAnswerByUser" parameterType="java.util.Map" resultType="Answer">
select * from answer where exercise_id=#{id} and user_email='#{user.email}'
</select>
where email is a variable of Class User.
And it throws:
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).
I have no idea about the exception.
CodePudding user response:
You are configuring the parameterType
to parameterType="java.util.Map"
when when you are passing two parameters User and Integer. Remove the parameterType="java.util.Map"
and it should map the parameterTypes
"automatically" based on the @Param
annotation. Or try with parameterType="map"