- Заменил шаблонизатор Mustache на Freemarker.
https://www.youtube.com/watch?v=8MlXahJXLFg&list=PLU2ftbIeotGpAYRP9Iv2KLIwK36-o_qYk&index=7
This commit is contained in:
@@ -3,5 +3,5 @@ spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/sweater_db
|
||||
spring.datasource.username=user
|
||||
spring.datasource.password=123456
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.mustache.servlet.expose-request-attributes=true
|
||||
|
||||
spring.freemarker.expose-request-attributes=true
|
||||
spring.freemarker.suffix=.ftl
|
||||
|
||||
5
src/main/resources/templates/greeting.ftl
Normal file
5
src/main/resources/templates/greeting.ftl
Normal file
@@ -0,0 +1,5 @@
|
||||
<#import "parts/common.ftl" as com>
|
||||
<@com.page>
|
||||
<div>Hello there</div>
|
||||
<a href="/main">Main page</a>
|
||||
</@com.page>
|
||||
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Getting Started: Serving Web Content</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<div>Hello there</div>
|
||||
<a href="/main">Main page</a>
|
||||
</body>
|
||||
</html>
|
||||
8
src/main/resources/templates/login.ftl
Normal file
8
src/main/resources/templates/login.ftl
Normal file
@@ -0,0 +1,8 @@
|
||||
<#import "parts/common.ftl" as com>
|
||||
<#import "parts/login.ftl" as l>
|
||||
|
||||
<@com.page>
|
||||
Login page
|
||||
<@l.login "/login" />
|
||||
<a href="/registration">Add new user</a>
|
||||
</@com.page>
|
||||
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Spring Security Example </title>
|
||||
</head>
|
||||
<body>
|
||||
Login page
|
||||
<form action="/login" method="post">
|
||||
<div><label> User Name : <input type="text" name="username"/> </label></div>
|
||||
<div><label> Password: <input type="password" name="password"/> </label></div>
|
||||
<div><input type="submit" value="Sign In"/></div>
|
||||
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
|
||||
</form>
|
||||
<a href="/registration">Add new user</a>
|
||||
</body>
|
||||
</html>
|
||||
36
src/main/resources/templates/main.ftl
Normal file
36
src/main/resources/templates/main.ftl
Normal file
@@ -0,0 +1,36 @@
|
||||
<#import "parts/common.ftl" as com>
|
||||
<#import "parts/login.ftl" as l>
|
||||
<@com.page>
|
||||
<div>
|
||||
<@l.logout />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form method="post">
|
||||
<input type="text" name="text" placeholder="Enter message" />
|
||||
<input type="text" name="tag" placeholder="tag">
|
||||
<input type="hidden" name="_csrf" value="${_csrf.token}" />
|
||||
<button type="submit">Add message</button>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<form method="get" action="/main">
|
||||
Tag to filer
|
||||
<br>
|
||||
<input type="text" name="tag" value="${tag}">
|
||||
<button>Find</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>Messages list</div>
|
||||
<#list messages as message>
|
||||
<div>
|
||||
<b>${message.id}</b>
|
||||
<span>${message.text}</span>
|
||||
<i>${message.tag}</i>
|
||||
<strong>${message.authorName}</strong>
|
||||
</div>
|
||||
<#else>
|
||||
No messages found
|
||||
</#list>
|
||||
</@com.page>
|
||||
@@ -1,39 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
|
||||
<div>
|
||||
<form action="/logout" method="post">
|
||||
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
|
||||
<input type="submit" value="Sign Out"/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form method="post">
|
||||
<input type="text" name="text" placeholder="Enter message"> </input>
|
||||
<input type="text" name="tag" placeholder="tag"></input>
|
||||
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
|
||||
<button type="submit">Add message</button>
|
||||
</form>
|
||||
</div>
|
||||
<div>
|
||||
<form method="post" action="filter">
|
||||
Tag to filer
|
||||
<br>
|
||||
<input type="text" name="tag">
|
||||
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
|
||||
<button>Find</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div>Messages list</div>
|
||||
{{#messages}}
|
||||
<div>
|
||||
<b>{{id}}</b>
|
||||
<span>{{text}}</span>
|
||||
<i>{{tag}}</i>
|
||||
<strong>{{authorName}}</strong>
|
||||
</div>
|
||||
{{/messages}}
|
||||
</body>
|
||||
</html>
|
||||
14
src/main/resources/templates/parts/common.ftl
Normal file
14
src/main/resources/templates/parts/common.ftl
Normal file
@@ -0,0 +1,14 @@
|
||||
<#macro page>
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Sweater</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<#nested>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</#macro>
|
||||
15
src/main/resources/templates/parts/login.ftl
Normal file
15
src/main/resources/templates/parts/login.ftl
Normal file
@@ -0,0 +1,15 @@
|
||||
<#macro login path>
|
||||
<form action="${path}" method="post">
|
||||
<div><label> User Name : <input type="text" name="username"/> </label></div>
|
||||
<div><label> Password: <input type="password" name="password"/> </label></div>
|
||||
<div><input type="submit" value="Sign in"/></div>
|
||||
<input type="hidden" name="_csrf" value="${_csrf.token}" />
|
||||
</form>
|
||||
</#macro>
|
||||
|
||||
<#macro logout>
|
||||
<form action="/logout" method="post">
|
||||
<input type="hidden" name="_csrf" value="${_csrf.token}" />
|
||||
<input type="submit" value="Sign Out"/>
|
||||
</form>
|
||||
</#macro>
|
||||
11
src/main/resources/templates/registration.ftl
Normal file
11
src/main/resources/templates/registration.ftl
Normal file
@@ -0,0 +1,11 @@
|
||||
<#import "parts/common.ftl" as com>
|
||||
<#import "parts/login.ftl" as l>
|
||||
|
||||
<@com.page>
|
||||
Registration page
|
||||
<br>
|
||||
<#if message??>
|
||||
${message}
|
||||
</#if>
|
||||
<@l.login "/registration" />
|
||||
</@com.page>
|
||||
@@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Spring Security Example </title>
|
||||
</head>
|
||||
<body>
|
||||
Registration page
|
||||
<br>
|
||||
{{#message}}
|
||||
{{message}}
|
||||
{{/message}}
|
||||
<form action="/registration" method="post">
|
||||
<div><label> User Name : <input type="text" name="username"/> </label></div>
|
||||
<div><label> Password: <input type="password" name="password"/> </label></div>
|
||||
<div><input type="submit" value="Add user"/></div>
|
||||
<input type="hidden" name="_csrf" value="{{_csrf.token}}" />
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user