spring boot 如何把html放到resource目录下

在aplication.yml中做如下配置:

spring:
    mvc:
      view:
        suffix: .html
        prefix: classpath:/temptales/
      static-path-pattern: /static/**

配置后resource和static 都相当于根路径/

css和js的引入如下:

<link rel="stylesheet" href="/bootstrap.min.css" type="text/css" />
<script type="text/javascript" src="/js/jquery-3.2.1.js"></script>

切记js引入不要向下面这样写,这是script标签的特殊之处:

<script type="text/javascript" src="/js/jquery-3.2.1.js" />

切记:

 

pom.xml添加如下依赖即可

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

关于静态资源加载问题在resource目录下创建static目录css、js、image放在改目录下做如下配置即可

引入不需要写static

<script type="text/javascript" src="/js/jquery-3.2.1.js"/>

网上也有说这样解决的,我没试,上面的肯定可以解决

原理上这种方案也不存在问题。

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要使用Java代码将Word文档转换为HTML格式。可以使用Apache POI library来读取和解析Word文档,然后使用Thymeleaf模板引擎来生成HTML代码。 以下是一个简单的示例代码: ``` import java.io.*; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.converter.core.*; import org.apache.poi.xwpf.converter.xhtml.*; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class WordToHtmlController { @GetMapping("/word-to-html") public String convertWordToHtml(Model model) throws Exception { // Load the Word document from the resource folder File inputFile = new ClassPathResource("word/document.docx").getFile(); InputStream inputStream = new FileInputStream(inputFile); XWPFDocument document = new XWPFDocument(inputStream); // Prepare the HTML converter XHTMLOptions options = XHTMLOptions.create(); OutputStream out = new ByteArrayOutputStream(); XHTMLConverter.getInstance().convert(document, out, options); // Set the converted HTML content to the model attribute model.addAttribute("htmlContent", out.toString()); return "word-to-html"; } } ``` 在这个示例中,我们使用了一个简单的Spring Boot控制器来处理`/word-to-html`请求,并将转换后的HTML内容放入模型属性中。我们还使用了`ClassPathResource`来读取位于`src/main/resources/word/document.docx`的Word文档。 接下来,我们需要在前端使用Vue.js来显示转换后的HTML内容。可以使用Vue.js的`v-html`指令来将HTML代码渲染到页面上。以下是一个简单的示例代码: ``` <template> <div> <div v-html="htmlContent"></div> </div> </template> <script> export default { data() { return { htmlContent: '' } }, mounted() { // Load the HTML content from the server fetch('/word-to-html') .then(response => response.text()) .then(htmlContent => { this.htmlContent = htmlContent; }); } } </script> ``` 在这个示例中,我们定义了一个Vue.js组件,并使用`v-html`指令将模型属性中的HTML代码渲染到页面上。我们还使用`fetch`函数从服务器加载HTML内容,并将其存储在Vue.js组件的数据属性中。 请注意,这个示例是一个简单的起点。如果你的Word文档包含复杂的格式和布局,你可能需要对代码进行调整以确保正确地转换为HTML格式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值