springboot加载templates下html

springboot加载templates下html

---------------------------------------------------------------------------------------------------------------------------------

 前端:如果thymeleaf版本过低,这里<meta charset="UTF-8">可能会报错

            因为没有结束的斜线自己加上<meta charset="UTF-8"/>即可

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
</head>
<body>

<input type="button" id="tiaozhuan" value="跳转" onclick="tiaozhuan1();">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>

    function tiaozhuan1(){

        location.href='tiaozhuanlogin';
    }



</script>
</body>
</html>

后台:

package com.example.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class LoginController {


    @RequestMapping("/login")
    public String show(){
        return "login";
    }
    @GetMapping("/tiaozhuanlogin")
    public String show2(){
        //这里login2 是个html
        return "login2";
    }

}

注意:注解使用的是@Controller

yml:


spring:
  datasource:
    name: test  #数据库名
    #url: jdbc:mysql://localhost:3306/test #url
    url: jdbc:mysql://localhost:3306/test?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2b8
    username: root  #用户名
    password: Aa12345%  #密码
    driver-class-name: com.mysql.cj.jdbc.Driver  #数据库链接驱动

    mybatis:
      mapper-locations: classpath*:mapper/*Mapper.xml  #配置映射文件
      type-aliases-package: com.example.test.bean #配置实体类
  #主要是下边这个thymeleaf的配置,上边是我数据源的配置,不用管
  #主要是下边这个thymeleaf的配置,上边是我数据源的配置,不用管
  #主要是下边这个thymeleaf的配置,上边是我数据源的配置,不用管
  thymeleaf:
    cache: false
    prefix: classpath:/templates/
    suffix: .html
    encoding: UTF-8
    content-type: text/html
    mode: HTML5


pom:

<!--thymeleaf模板引擎配置-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值