1
我想創建一個spring mvc rest調用,響應應該是mongo db(Basic)DBObject的結果。據我所知,DBObject是一個JSON對象。是否有可能返回這個對象,或者我應該返回它們的正常字符串內容?spring mvc rest mongo dbobject response
這是解決方案,我至今:
@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
也沒人有一個線索,我有什麼問題? –