我有一个REST服务,我想访问它,并在浏览器的新行上打印出列表的每个元素。这是代码:
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String getAlerts(@RequestParam(value="code") String code) {
StringBuilder sBuffer = new StringBuilder();
for(Identity identity : service.getIdentityList(code)) {
sBuffer.append(identity.toString());
sBuffer.append(System.getProperty("line.separator"));
}
return sBuffer.toString();
}
该服务可以执行所有操作,并且列表会打印出来,但仅显示为1行。我希望将其打印在单独的行上。我怎么做?我不认为sBuffer是要走的路...我什至尝试过:
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String getAlerts(@RequestParam(value="code") String code) {
List<Identity> identityList = service.getIdentityList(code);
return identityList.toString();
}
但是它仍然在浏览器中打印为1行。...有关如何执行我想要的操作的任何想法?
在浏览器中,您需要使用<br>
换行符。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句