Mybatis总结(7)select查询结果封装为map

1.查一条
将单独的一条数据中每一对属性名/属性值对应map中的key/value查出来
{seller=6, gender=1, name=张三, tel=qqq, id=22, customerSource=1, status=已跟进}

    <select id="getCustomerMap" resultType="map">
        SELECT * FROM t_customer WHERE id = #{id}
    </select>
    Map<Integer, Object> getCustomerMap(Long id);

2.查一条或多条
指定查询出来的数据按什么属性封装到map中,比如姓名
{张三=Customer{name=‘张三’, age=null, gender=1, tel=‘qqq’, email=‘null’, qq=‘null’, wechat=‘null’, seller=null, job=‘null’, salaryLevel=null, customerSource=null, inputUser=‘null’, inputTime=‘null’, status=‘已跟进’, Tenant=‘null’}}

    <select id="getCustomerMap2" resultType="Customer">
        SELECT * FROM t_customer WHERE id = #{id}
    </select>
    /* 指定map中的key */
    @MapKey("name")
    Map<Integer, Customer> getCustomerMap2(Long id);

你可能感兴趣的:(Mybatis)