thymeleaf在springboot中的简单应用

resources目录下新建一个public目录,public目录下放一个html文件:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
</head>
<body>
  <div class="wrap">
    <button class="btn">点击1</button>
  </div>
  <div class="wrap">
    <button class="btn">点击2</button>
  </div>
</body>
<style>
</style>
<script>
$(document).ready(function(){
  $('.btn').on('click', function () {
    $.get("https://xxxx/xx/xxx", function(result){
      console.log(result)
    })
  })
});

</script>
</html>

springboot的properties文件中配置属性:

spring.thymeleaf.prefix=classpath:/public/

添加thymeleaf依赖:

        <!--引入thymeleaf依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

完成以上步骤,springboot项目中就可以访问html文件了。


版权声明:本文为jll126原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。