通过map传递参数

UserMapper

public int updateUserByMap(Map map);

UserMapper.xml

<update id="updateUserByMap" parameterType="map">
    update mybatis.user set  name=#{username}  where id=#{id};
</update>

Test

@Test
public void testUpUserByMap(){
    //第一步:获得sqlSession对象
    SqlSession sqlSession = MybatisUtils.getSqlSession();
    //第二步:执行sql
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    HashMap<String, Object> map = new HashMap<>();
    map.put("username","乔晓斌");
    map.put("id",1);
     mapper.updateUserByMap(map);
    sqlSession.commit();


    //第三步:关闭sqlSession
    sqlSession.close();
}
posted @ 2022-05-25 20:40  qiaoyizhi  阅读(217)  评论(0编辑  收藏  举报