Mybatis parameterType

정재현·2022년 2월 14일

Mybatis를 사용하면서 여러개의 parameter를 받아 처리하고 싶어지는 상황이 있었다.
이 경우 Map에 파라미터를 세팅해서 보내주는 방법으로 해결.

Map에는

Map<String, Object> map = new HashMap<>();
int userId = board.getUserId();
double score = 5;
map.put("userId", userId);
map.put("score", score);

위와 같은 정보를 넣어 주고 xml파일에서

    <update id="setPoint" parameterType="map">
        update user
        set point= point + #{score}
        where id=#{userId}
    </update>

map에서 설정한 key값을 설정해주면 key에 해당하는 value가 설정된다.

profile
back end개발자로 성장하기

0개의 댓글