All of My Records

[Error] MyBatis 에러 :: Available parameters are [arg1, arg0, param1, param2]

by 캐떠린

❓ Problem: Available parameters are [arg1, arg0, param1, param2]

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'date' not found. Available parameters are [arg1, arg0, param1, param2]

 

Spring 프로젝트 코드를 수정하던 중 mapper.xml에서 작성한 쿼리문에서 오류가 발생했다. Mapper Interface에서 Parameter로 (String seq, String date)를 보내고 MyBatis에서 parameterType="String"을 설정한 후, 쿼리문에서 #{seq}, #{date}를 사용하는데 date를 찾을 수 없다고 한다.

 

Mapper.java(Interface)

List<MoviePlayDTO> getMoviePlayListBySeq(String seq, String date);

 

Mapper.xml

<select id="getMoviePlayListBySeq" parameterType="String" resultType="com.project.dd.activity.movieplay.domain.MoviePlayDTO">
    select * from vwMoviePlayList
    where close = 'n'
    and movie_seq = #{seq}
        <if test="date == 'sysdate'">
        and to_char(sysdate, 'yyyy-mm-dd') between start_date and end_date)
        </if>
        <if test="date != 'sysdate'">
        and #{date} between start_date and end_date)
        </if>
</select>

 

String으로 여러개 보내도 파라미터명만 정확하게 쓰면 가져올 줄 알았는데 date를 찾을 수 없다고 한다. 왜지? date를 주석처리해봤더니 seq를 찾을 수 없다고 한다.

Map에 넣어서 보낼까 하다가 같은 String 이니까 이렇게 해보려 했던건데..

 

❗ Solution

결국 Map에 seq, date를 넣어서 파라미터로 보냈더니 정상 작동한다.

 

Service.java

public List<MoviePlayDTO> getMoviePlayListBySeq(String seq, String date) {

    Map<String, String> map = new HashMap<String, String>();

    map.put("seq", seq);
    map.put("date", date);

    return dao.getMoviePlayListBySeq(map);
}

 

Mapper.java(Interface)

List<MoviePlayDTO> getMoviePlayListBySeq(Map<String, String> map);

 

Mapper.xml

<select id="getMoviePlayListBySeq" parameterType="map" resultType="com.project.dd.activity.movieplay.domain.MoviePlayDTO">
    select * from vwMoviePlayList
    where close = 'n'
    and movie_seq = #{seq}
        <if test="date == 'sysdate'">
        and to_char(sysdate, 'yyyy-mm-dd') between start_date and end_date
        </if>
        <if test="date != 'sysdate'">
        and #{date} between start_date and end_date
        </if>
</select>

블로그의 정보

All of My Records

캐떠린

활동하기