首先,同一条sql,在数据库中执行,和在项目中执行,结果不一样。idea打印的结果,显示的条数是正常的。但list里的结果更少了。
这是因为映射的问题。我之前的映射配置如下:
<resultMap type="com.server.***.NoticeVO" id="NoticeVO">
<result property="projectName" column="project_name"/>
<result property="sectionName" column="section_name"/>
<association property="notifyRecord" javaType="com.server.***.model.NotifyRecord">
<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="deleted" column="deleted"/>
</association>
</resultMap>
内容不是关键,关键是我并没有设置映射主键,所以在映射的时候,mybatis会把一些内容差不多(自行摸索)的映射成一条记录。所以最后结果变少了。现在改一下:
<resultMap type="com.server.***.NoticeVO" id="NoticeVO">
<id column="id" property="notifyId"/>
<result property="projectName" column="project_name"/>
<result property="sectionName" column="section_name"/>
<association property="notifyRecord" javaType="com.server.***.model.NotifyRecord">
<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="deleted" column="deleted"/>
</association>
</resultMap>
ok。