添加person表的记录

insert into person values(2, '吕布', 1, '东汉', '2014-11-11');  

QueryCondition自定义类

public class QueryCondition {  
    private Integer gender;
    private Date birthday;
    // ... get set
}

PersonMapper.xml

<!-- 查询所有的用户 -->  
<select id="selectPersonAll" resultMap="personResultMap">  
    select * from person
</select>  
<!--  
    传递自定义的对象参数
 -->
<select id="selectPersonByParams" parameterType="com.itbto.mode1.QueryCondition" resultMap="personResultMap">  
    <!-- 
        使用<![CDATA[]]>原样显示特殊字符
        必须正确指定参数对应的QueryCondition属性 
    -->
    <![CDATA[
    select * from person t where t.gender=#{gender} and t.birthday<#{birthday}
    ]]>
</select>

<!-- 使用map集合对象作为参数 -->  
<select id="selectPersonByParams1" parameterType="java.util.Map" resultMap="personResultMap">  
    <![CDATA[
    select * from person t where t.gender=#{gender} and t.birthday<#{birthday}
    ]]>
</select>

<!-- 模糊查询 -->  
<select id="selectPersonByName" parameterType="java.util.Map" resultMap="personResultMap">  
    select * from person t where t.name like '%${name}%'
</select>  

测试方法

@Test
public void testSelectPersonAll(){  
    SqlSession session = sessionFactory.openSession();
    try {
        List<Person> pList = session.selectList("com.itbto.mapper.PersonMapper.selectPersonAll");
        for(Person p : pList){
            System.out.println(p);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally{
        session.close();
    }
}

@Test
public void testSelectPersonByParams(){  
    SqlSession session = sessionFactory.openSession();

    QueryCondition qc = new QueryCondition();
    qc.setGender(1);
    qc.setBirthday(new Date());

    try {
        List<Person> pList = session.selectList("com.itbto.mapper.PersonMapper.selectPersonByParams", qc);
        for(Person p : pList){
            System.out.println(p);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally{
        session.close();
    }
}

@Test
public void testSelectPersonByParams1(){  
    SqlSession session = sessionFactory.openSession();

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("gender", 1);
    map.put("birthday", new Date());

    try {
        List<Person> pList = session.selectList("com.itbto.mapper.PersonMapper.selectPersonByParams1", map);
        for(Person p : pList){
            System.out.println(p);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally{
        session.close();
    }
}

@Test
public void testSelectPersonByName(){  
    SqlSession session = sessionFactory.openSession();

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("name", '满');

    try {
        List<Person> pList = session.selectList("com.itbto.mapper.PersonMapper.selectPersonByName", map);
        for(Person p : pList){
            System.out.println(p);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally{
        session.close();
    }
}