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中。