2.1 定义dao
提前定义好我们的dao,这里参数用 map传递
public interface UserDao {User findUser(Map<String, Object> map);}
2.2 编写mapper文件
当我们使用map时这里的参数就可以自己指定
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!--绑定对应的dao接口--><mapper namespace="com.lu.dao.UserDao"><select id="findUser" parameterType="map" resultType="com.lu.entity.User">select *from userwhere id = #{userID};</select></mapper>
2.3 测试
单元测试,这里使用也是传递一个map
@Testpublic void mapQuery() {Map<String, Object> param = new HashMap<>();param.put("userID", 3);User user = mapper.findUser(param);System.out.println(user);}
