mapper接口中写的方法的返回值为List的对象数组

首先需要在mapper.xml中映射一个resultmap,column为类中的属性也就是表中所对应的字段。
代码如下:
<resultMap id="seeShare" type="com.example.demo.entity.Diary">
<id column="id" property="id" />
<result column="title" property="title" />
<result column="content" property="content" />
<result column="writeTime" property="writeTime" />
<result column="username" property="username" />
</resultMap>
然后写具体的查询
<select id="selectShare" resultMap="seeShare">
SELECT * FROM Diary
</select>
通过这样配置,查询返回的结果集就会存储到list中。
本文详细介绍如何在MyBatis中配置List类型的查询结果。通过定义resultMap,将查询结果映射到实体类属性,实现从数据库获取多条记录并存储到List中。
714

被折叠的 条评论
为什么被折叠?



