iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Springboot中静态文件的两种引入方式总结
  • 316
分享到

Springboot中静态文件的两种引入方式总结

2024-04-02 19:04:59 316人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

目录thymeleaf 模式依赖中引入可选配置yml 做如下配置构架这样构架非thymeleaf 模式首先去掉依赖删除controller的指向view层yml文件中这样配置&nbs

thymeleaf 模式

依赖中引入

<!-- 渲染静态页面 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

可选配置

如果你有

WEBmvcConfigurationSupport 的一些类引用. 你需要放行他们

如果你引用了 springSecurity

你也需要放行他们

thymeleaf 需要通过controller层转向view 层  

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class IndexController {
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public ModelAndView index() {
        System.out.println("/index进入controller控制器");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }
    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public ModelAndView home() {
        System.out.println("/home进入controller控制器");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }
    @RequestMapping(value = "/error", method = RequestMethod.GET)
    public ModelAndView error() {
        System.out.println("/error进入controller控制器");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login() {
        System.out.println("/login进入controller控制器");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView indexs() {
        System.out.println("/ 进入controller控制器");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }
    @RequestMapping(value = "/404", method = RequestMethod.GET)
    public ModelAndView error404() {
        System.out.println("/404 进入controller控制器");
        ModelAndView mav = new ModelAndView();
        mav.setViewName("index");
        return mav;
    }
}

yml 做如下配置

构架这样构架

非thymeleaf 模式

首先去掉依赖

删除controller的指向view层

如果你想带控制器也是可以的   (带的话 指向index. 不带的话 默认指向index .可以理解成一个绝对路径,一个相对路径)

yml文件中这样配置 

是为了能够直接访问 根目录下的text文件 

构架如下

完成.

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

--结束END--

本文标题: Springboot中静态文件的两种引入方式总结

本文链接: https://www.lsjlt.com/news/143054.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作