Java中读取html文件转成String,展示在浏览器

第一章

1.1)pom中引入依赖和html文件示例

引入hutool工具包依赖

 		<dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.6.2</version>
        </dependency>

html文件路径../SpringBootTest/001-test/content.html

<html>
<body>
<h2>工作整改</h2>
</body>

<head>
    <style>  .bold-red {
        color: red;
        font-weight: bold;
    }</style>
</head>
<body><p>各位:</p>
<p>本周安全管理工作安排:</p>
<p>重点关注附件<span class="bold-red">完成整改工作</span></p>
<p>加油</p>
</body>
</html>

1.2)使用hutool工具包读取html文件转为string

@Slf4j
@Controller
public class ControllerTest {

    //http://localhost:9001/001-test/springBoot/test
    @RequestMapping(value = "/springBoot/test")
    @ResponseBody
    public String say() {
            try {
                File content = ResourceUtils.getFile("../SpringBootTest/001-test/content.html");
                return FileReader.create(content).readString();
            } catch (FileNotFoundException e) {
                log.error("0.0", e);
            }
            return "没有读取到html文件";
        }
    }

1.3)页面显示

在这里插入图片描述

  • 8
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值