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

37 篇文章 0 订阅
16 篇文章 0 订阅

不同操作系统的换行符

跨平台的

System.getProperty("line.separator");

windows平台

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

Unix/Linux平台

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

Mac系统

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

字符串放在中

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

举例说明

package com.hutool.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.hutool.system.SystemUtil;
@RestController
public class HutoolControl {
    @RequestMapping("/hutooldemo")
    public String index() {
        StringBuilder sb = new StringBuilder();
        sb.append("<pre>");
        sb.append("Hello, Hutool Demo 5.7!");
        sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
        sb.append(SystemUtil.getHostInfo().toString());
        sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
        sb.append(SystemUtil.getJavaRuntimeInfo().toString());
        sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
        sb.append("goodbye,Hutool!");
        sb.append(System.getProperty("line.separator")+"----------------------------------"+System.getProperty("line.separator"));
        sb.append("<pre>");
        return sb.toString();
    }
}
  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值