使用场景
我这里的业务场景是:有字典表,其他表的很多字段都需要去字典表中查询,由于字典表的维护方便统一,所以将其他表对字典值的查询单独抽出来,那么我们可以将每次需要查询字典值的id拿到一起,直接查询字典信息,用map接收字典的内容,将id做为key,很方便拿到。
dao层
@MapKey("id")
Map<String,UserInfoEntity> selectUser();
mybatis的xml文件
<select id="selectUser" resultMap="userInfo">
select * from user_info
</select>
<resultMap id="userInfo" type="com.make.study.entity.UserInfoEntity">
<!--由于我的查询和接受的实体字段相同,所以没有写映射-->
</resultMap>