文章详情

最近要做一个java web项目,因为页面不是很多,所以就没有前后端分离,前后端写在一起,这时候就用到thymeleaf了,以下是不动脑式的傻瓜教程。。。。。

一:创建spring boot的web项目,过程略;

二:依赖如下:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

三:配置文件:application.properties

#端口号
server.port=8099
# 配置
#thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.check-template-location=true
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.mode=HTML

四:项目的templates文件夹下新建页面success.html,如下

五:controller

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @author liuhongyang
* @2020/10/20 14:35
* 文件说明:
*/
@Controller
public class FirstTestController {
@RequestMapping(value = "hello")
public String hello(ModelMap modelMap) {
modelMap.put("hei", "thymeleaf");
return "success";
}
}

六:访问如下,完成

您可能感兴趣的文章:

  • springboot themaleaf 第一次进页面不加载css的问题
  • SpringBoot配置绑定方法详解
  • SpringBoot本地磁盘映射问题
  • SpringBoot参数校验与国际化使用教程
  • SpringBoot在yml配置文件中配置druid的操作
  • SpringBoot一个非常蛋疼的无法启动的问题解决
  • springboot中JSONObject遍历并替换部分json值
  • 在idea中显示springboot面板的方法

版权:版权申明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 70068002@qq.com 举报,一经查实,本站将立刻删除。

转载请注明出处:https://www.stntk.com/2579.html

相关推荐
php数据库怎样去重复的数据
当涉及到数据库去重功能时,PHP可以与数据库交互并执行相应的操作。以下是一个示例的PHP代码,用于从数据库中删除重复的记录并保留唯一的数据:…
头像
后端开发 2024-05-26
1,022
如何在 Python 中使用 try…else 块
在 Python 编程中,我们经常会遇到需要处理异常的情况。使用 try…except 块是一种常见的处理方法,它可以捕获和处理代码中可能出…
头像
后端开发 2024-05-26
1,319
php发送/显示 base64 编码图像
我需要向客户端发送一个 base64 编码的字符串。因此,我打开并读取服务器上的图像文件,对其进行编码并将该数据与 image/jpeg 内…
头像
后端开发 2024-05-26
11,528
php 生成条形码(支持任意php框架)
一:插件安装 在php中我们可以使用php-barcode-generator插件来生成条形码,php-barcode-generator插…
头像
后端开发 2024-05-26
986
如何在ThinkPHP6中使用队列技术
ThinkPHP 6(TP6)是一个流行的PHP框架,它提供了一些有用的工具和组件,其中之一就是队列(Queue)服务。队列是一种用于异步处…
头像
后端开发 2024-05-26
1,575
cURL error 60: SSL certificate problem: unable to get local issuer certificate 解决方法
fastadmin开发小程序登录功能报错: cURL error 60: SSL certificate problem: unable t…
头像
后端开发 2024-05-26
1,089
发表评论
暂无评论

还没有评论呢,快来抢沙发~

点击联系客服

在线时间:8:00-16:00

客服电话

400-888-8888

客服邮箱

70068002@qq.com

扫描二维码

关注微信公众号