java中后端字符串换行及格式,如何返回前台页面?

绝地灬酷狼 2022-09-11 10:18 397阅读 0赞

字符串的换行及格式控制

  • 不同操作系统的换行符
    • 跨平台的
    • windows平台
    • Unix/Linux平台
    • Mac系统
  • 字符串放在中
  • 举例说明

不同操作系统的换行符

跨平台的

  1. System.getProperty("line.separator");

windows平台

Windows系统里面,每行结尾是“<回 车><换行>”,即“\r\n”;

Unix/Linux平台

Unix系统里,每行结尾只有“<换行>”,即“\n”;

Mac系统

Mac系统里,每行结尾是“<回车>”。

字符串放在中

  1. 即在整个字符串的格式:【<pre>+字符串+</pre>】

举例说明

  1. package com.hutool.demo;
  2. import org.springframework.web.bind.annotation.RequestMapping;
  3. import org.springframework.web.bind.annotation.RestController;
  4. import cn.hutool.system.SystemUtil;
  5. @RestController
  6. public class HutoolControl {
  7. @RequestMapping("/hutooldemo")
  8. public String index() {
  9. StringBuilder sb = new StringBuilder();
  10. sb.append("<pre>");
  11. sb.append("Hello, Hutool Demo 5.7!");
  12. sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
  13. sb.append(SystemUtil.getHostInfo().toString());
  14. sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
  15. sb.append(SystemUtil.getJavaRuntimeInfo().toString());
  16. sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
  17. sb.append("goodbye,Hutool!");
  18. sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
  19. sb.append("<pre>");
  20. return sb.toString();
  21. }
  22. }

发表评论

表情:
评论列表 (有 0 条评论,397人围观)

还没有评论,来说两句吧...

相关阅读