org.springframework.data.repository.query.Param;和org.apache.ibatis.annotations.Param;区别
程序员文章站
2022-05-24 12:00:24
...
eg:
List<String> getIdByStatus(@Param("status") String status, @Param("num") int num); 当你import的是org.springframework.data.repository.query.Param;时,对应的你在xml里面要用arg0,arg1分别表示第一个参数,第二个参数来取值。
<select id="getIdByStatus" resultType="String">
select id from t_illega_parking_info t
where t.STATUS = #{arg0,jdbcType=VARCHAR}
order by t.ILLEGAL_TIME limit #{arg1}
</select>
当你import的是org.apache.ibatis.annotations.Param;时,对应的xml里面你需要对应的名字来取值
<select id="getIdByStatus" resultType="String">
select id from t_illega_parking_info t
where t.STATUS = #{status,jdbcType=VARCHAR}
order by t.ILLEGAL_TIME limit #{num}
</select>
如果你用的spring的注解,但是xml是用名字来取值,就会报下面的错误
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'status' not found. Available parameters are [arg1, arg0, param1, param2]
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy81.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:139)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:76)