【发布时间】:2018-10-23 15:50:42
【问题描述】:
我有一个 mybatis resultMap 引用一个 POJO 类,如下所示。
<resultMap id="FolderResultMap" type="Folder">
<result column="recordcount" property="recordCount" />
<result column="contenttype" property="folderContentType" />
<result column="folderid" property="folderId" />
<result column="folderdesc" property="folderDescription" />
<result column="foldername" property="folderName" />
<result column="foldertype" property="folderType" />
</resultMap>
<select id="findReportFolders" resultMap="FolderResultMap">
some query
</select>
在我的 Mapper 界面中
List<Folder> findReportFolders (@Param("name") long id,
@Param("id2") long busid);
因此,我得到 JSON 响应作为对象列表,我需要如下所述的对象列表映射。
{
"folders": [
{
"recordCount": 7,
"folderContentType": "Reports",
"folderId": 139491,
"folderDescription": null,
"folderName": "AA_TestPrivateFolder1234",
"folderType": "CUSTOM",
"refreshable": true
},
{
"recordCount": 35,
"folderContentType": "Reports",
"folderId": 140109,
"folderDescription": "Default Folder for New Reports",
"folderName": "label.privateReportInboxOverrideName",
"folderType": "INBOX",
"refreshable": true
}]
}
这就是我现在得到的。我想得到如上的回复。
[{"folderId":359056,"folderName":"BE Shared Report Inbox","folderDescription":"BE Shared Report Inbox","folderType":"INBOX","folderContentType":"SharedReports","recordCount":0,"refreshable":true},{"folderId":363984,"folderName":"Default Inbox Folder","folderDescription":"Default Folder for New Reports","folderType":"INBOX","folderContentType":"Reports","recordCount":0,"refreshable":true}]
任何想法我该怎么做?
【问题讨论】:
-
问题不清楚。首先,mybatis 不会为你创建 JSON。你从映射器中得到
Folders 的列表,然后你做一些事情来获取 JSON。你是怎样做的?您是否正在寻找 Spring MVC 为您执行的该列表的序列化输出?下一个问题是你现在得到的格式是什么,你想得到什么,请两者都包含。