示例:根据密码和名字查询用户
传统的普通参数
//接口中的参数username, pwd
User selectUserByNameAndPwd(@Param("username") String username,@Param("pwd") String pwd);
<select id="selectUserByNameAndPwd1" resultType="com.tz.pojo.User">
select * from user where name = #{username} and pwd = #{pwd}
</select>
万能的map
1.在接口方法中传参,直接传递Map
User selectUserByNameAndPwd2(Map<String,Object> map);
2.编写sql语句的时候,paramterType="map"
<select id="selectUserByNameAndPwd2" parameterType="map" resultType="com.tz.pojo.User">
select * from user where name = #{username} and pwd = #{pwd}
</select>
3.测试
Map<String, Object> map = new HashMap<String, Object>();
map.put("username","张三");
map.put("pwd","123456");
User user = mapper.selectUserByNameAndPwd2(map);
好处:减少参数更直观,参数的顺序没有要求,map中只要key对应相应的value就可以了