最近自己搭建的ssm框架,做了一个增删改查的功能。在做查询一条数据修改数据会显的时候,出现的一个错,
下面是详细的错误信息:
HTTP Status 500 - Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='emp_id', 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).
我写的代码是这样的:
<resultMap id="ReturnOneResultMap" type="com.dev.bean.Employee">
<id column="emp_id" jdbcType="INTEGER" property="emp_id" />
<result column="emp_name" jdbcType="VARCHAR" property="emp_name" />
<result column="sex" jdbcType="CHAR" property="sex" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="position" jdbcType="VARCHAR" property="position"/>
<!-- 使用association指定查询部门字段的封装 -->
<association property="department" javaType="com.yhhy.bean.Department">
<id column="department_id" jdbcType="VARCHAR" property="department_id" />
<result column="department_name" jdbcType="VARCHAR" property="department_name" />
</association>
</resultMap>
<select id="getOneInfoById" resultMap="ReturnOneResultMap">
SELECT a.emp_id,a.emp_name,a.sex,a.email,a.position,b.department_id,b.department_name FROM employee a LEFT JOIN department b ON a.department_id = b.department_id
WHERE a.emp_id = #{emp_id}
</select>
修改完后是这样的:
<resultMap id="ReturnOneResultMap" type="com.dev.bean.Employee">
<id column="emp_id" jdbcType="INTEGER" property="emp_id" />
<result column="emp_name" jdbcType="VARCHAR" property="emp_name" />
<result column="sex" jdbcType="CHAR" property="sex" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="position" jdbcType="VARCHAR" property="position"/>
<association property="department" javaType="com.yhhy.bean.Department">
<id column="department_id" jdbcType="VARCHAR" property="department_id" />
<result column="department_name" jdbcType="VARCHAR" property="department_name" />
</association>
</resultMap>
<select id="getOneInfoById" resultMap="ReturnOneResultMap">
SELECT a.emp_id,a.emp_name,a.sex,a.email,a.position,b.department_id,b.department_name FROM employee a LEFT JOIN department b ON a.department_id = b.department_id
WHERE a.emp_id = #{emp_id}
</select>
出现这个错误让我百思不得其解,我发现我写的接口和各种配置都没有问题,但是一直报这个错,耗费我很长时间。
仅仅把mybatis association的标签上面的注释去掉就好了。最后可以回显了。成功
希望我的答案能帮助到遇到这样问题的各位的开发者们。