Cause: java.sql.SQLException: Parameter index out of range (2 > number of parameters,which is 1).

最近自己搭建的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的标签上面的注释去掉就好了。最后可以回显了。成功

希望我的答案能帮助到遇到这样问题的各位的开发者们。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值