关于mybatis参数传递问题(Parameter 'arg0' not found. )

今天打开项目无意间 在maven中点了一下clean。之后启动项目出现了
Parameter 'arg0' not found.
这样的报错。
原因是mybatis新版又改成了以参数名使用:

where manager_id = #{managerId}

旧版传参形势:

where manager_id = #{arg0}

已经停用。
这是因为在mybatis早期,参数没做注解时默认是按顺序获取,以0、1等为索引,而后来由0、1改为用arg0、arg1代替。
现在新版又重新改回了参数名进行传递。
不过避免不必要的麻烦,mybatis传参还是推荐使用参数注解的方法进行参数的传递:

public int insertOrderMapProducts(@Param("orderId") int orderId, @Param("productsId") int productsId,
			@Param("amount") int amount);

这样的话,在mapper中就可以正常使用参数名了,如下:

<insert id="insertOrderMapProducts" parameterType="int">
		INSERT
		INTO
		shop_orderandproducts(orderId,productsId,amount)
		VALUES
		(#{orderId},#{productsId},#{amount});
	</insert>

猜你喜欢

转载自blog.csdn.net/qq_30833275/article/details/86304719