[Spring] org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException

eunoia73·2024년 6월 13일

trouble shooting

목록 보기
3/16

❗️ 에러문구

  • Failed to complete request: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'boardSeq' not found. Available parameters are [arg2, arg1, arg0, param3, param1, param2]

  • [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'boardSeq' not found. Available parameters are [arg2, arg1, arg0, param3, param1, param2]]

💡 에러 해결 방법

  • 게시판 좋아요 기능 구현 중 발생

  • @Param 어노테이션을 사용하면, 명시적으로 파라미터 이름을 지정할 수 있어 SQL 쿼리에서 가독성이 좋아지고 유지보수가 용이하다.

  • @Param 어노테이션을 사용하지 않으면, MyBatis는 기본 이름(arg0, arg1, arg2)을 사용하여 파라미터를 참조한다.

<select id="existsLike" parameterType="map" resultType="int">
  SELECT COUNT(*) FROM likes WHERE board_seq = #{arg0} AND board_type_seq = #{arg1} AND member_seq = #{arg2}
</select>

@Param을 사용하지 않으면, 이런 식으로 사용해야 한다!

  • 이전 코드
public int deleteLike(int boardSeq, int boardTypeSeq, int memberSeq);
  • 변경된 코드
public int deleteLike(@Param("boardSeq") int boardSeq,  @Param("boardTypeSeq") int boardTypeSeq, @Param("memberSeq") int memberSeq);

0개의 댓글