thymeleaf

springboot集成thymeleaf

添加依赖
在这里插入图片描述

    <!-- thmyeleaf -->
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-thymeleaf</artifactId>	
	</dependency>

配置thymeleaf application.properties文件
在这里插入图片描述

#thymeleaf 配置
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#缓存设置为false
spring.thymeleaf.cache=false

编写接口
在这里插入图片描述

	/*
	 * 登录页面
	 */
	@RequestMapping("/toLogin")
	public String toLogin(Model m){
		return "login";
	}

编写thymeleaf页面 login.html

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>login</title>
    <script type="text/javascript" th:src="@{/jquery-3.4.1-min.js}"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <style>
    	body{
    		text-align:center;
    	}
    </style>
</head>
<body>
	<table>
		<tr>
			<td>账号:</td>
			<td><input type="text" id="username" /></td>
		</tr>
		<tr>
			<td>密码:</td>
			<td><input type="password" id="password" /></td>
		</tr>
		<tr>
			<td colspan="2"><button id="login">登录</button></td>
		</tr>
	</table>
</body>
<script type="text/javascript">
	$('#login').click(function(){
		$.ajax({
			url:'http://localhost:8080/login',
			data:{
				username: $('#username').val(),
				password: $('#password').val(),
			},
			success:function(r){
				alert(r);
			}
		})
	})
</script>
</html>

测试
在这里插入图片描述
项目目录
在这里插入图片描述
下一篇:shiro集成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值