1
私はspring mvc rest callを作成したいと思います。レスポンスはmongo db(Basic)DBObjectの結果でなければなりません。 DBObjectは、私が知る限り、JSONオブジェクトです。このオブジェクトを返すことは可能ですか、またはそれらの通常の文字列コンテンツを返す必要がありますか?spring mvc rest mongo dbobjectレスポンス
これは私がこれまで持っているソリューションです。
@RequestMapping(value = "/content/json/{ids}", method = RequestMethod.GET)
public ResponseEntity<String> getContentByIdsAsJSON(@PathVariable("ids") String ids)
{
String content = null;
StringBuilder builder = new StringBuilder();
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.add("Content-Type", "text/html; charset=utf-8");
List<String> list = this.contentService.findContentByListingIdAsJSON(ids);
if (list.isEmpty())
{
content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><error>no data found</error>";
return new ResponseEntity<String>(content, responseHeaders, HttpStatus.CREATED);
}
for (String json : list)
{
builder.append(json + "\n");
}
content = builder.toString();
return new ResponseEntity<String>(content, responseHeaders, HttpStatus.CREATED);
}
、誰もがその要件のためのよりよい解決策がありますか?
thxです。 simon
は誰ものための手掛かりを持っていないんもう少し基本概念を学ばなければならないと思う私一種の問題? –