zoukankan      html  css  js  c++  java
  • springboot配置html页面

     最近写了一下springboot , 碰到了一个配置 html 的问题 , 专门 记录一下

      首先 说明 , 有两种 访问html 的方式 

    1.通过后台跳转到 html 页面 

       现在比较流行的开发模式就是 前后端分离,  在分离的情况下 , 就无法直接访问到 html  , 需要通过 后端来跳转

    (1.) 添加maven

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

    (2.) 配置 application.yml

    spring:
    thymeleaf:
    prefix:
    classpath: /templates # 访问template下的html文件需要配置模板,映射
    cache: false # 开发时关闭缓存,不然没法看到实时页面

    (3) controller

    @Controller
    @RequestMapping("/delete/")
    public class deleteController {
    
        @RequestMapping("wrong")
        public String index() {
            return "wrong";
        }
    }

    注意 : 

    访问方法跳转页面 方法请求加/  返回到某一个页面不用.后缀名 并且类上的注解改为@controller 不是@rest Controller

    通过访问 localhost:8080/delete/wrong   就可以访问到 templates下的wrong.html页面.

    2.直接访问 html 页面

    配置applicaiton.yml

    不用通过方法访问页面
    spring:
      resources:
        static-locations: classpath:/static/, classpath:/templates/

    就可以通过 localhost:8080/wrong.html 访问

    感谢  知知.

  • 相关阅读:
    wait/sleep/yield的区别
    54点提高PHP编程效率(转)
    ftp 使用
    转义 html 里特殊含义字符
    查看端口是否被占用
    webservice 获取调用者IP
    字符编码
    你有读过软件的协议或是网站的服务条款吗?
    使用TSQL的Rand函数生成随机数的艰苦历程
    几个.NET方面的问题——参考答案
  • 原文地址:https://www.cnblogs.com/Anonymity-zhang/p/13398656.html
Copyright © 2011-2022 走看看