Spring teplates. Thymeleaf & spring framework презентация

Содержание

Слайд 2

History

History

Слайд 3

Servlets Hello! public class HelloWorldServlet extends HttpServlet { protected void

Servlets

Hello!

public class HelloWorldServlet extends HttpServlet {
protected void doGet(request, response) {


response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(""); out.println(""); out.println("Hello!"); out.println("");
out.println("");
out.println("");
out.println("");
}
}

Html symbols are writing directly to the browser from java code.

Слайд 4

Servlets Hello! public class HelloWorldServlet extends HttpServlet { protected void

Servlets

Hello!

public class HelloWorldServlet extends HttpServlet {
protected void doGet(request, response) {


request.getRequestDispatcher("/login.jsp").
forward(request, response);
}
}

Html code saved separately from java code
and can be dynamically changed before sending to browser . It’s good.



Hello!


Hello!


");

Слайд 5

Java Servlet-JSP Architecture Server Hello World! Java Jasper JSPs Servlet container

Java Servlet-JSP Architecture


Server

Hello World!

Java

Jasper

JSPs

Servlet container

Слайд 6

Templates

Templates

Слайд 7

Template – document or parts of document with basic configuration.

Template – document or parts of document with basic configuration.


Table
with

dynamic content

Left menu

Spam

Header

Footer

Слайд 8

Spring templates. Apache Velocity FreeMarker Rythm Thymeleaf 3.8 seconds 4.8

Spring templates.

Apache Velocity
FreeMarker
Rythm
Thymeleaf

3.8 seconds
4.8 seconds
3 seconds
43.2 seconds

Results obtained after testing with

benchmarking tool
for 10000 requests.
Слайд 9

Thymeleaf. Thymeleaf integration with Spring framework.

Thymeleaf. Thymeleaf integration with Spring framework.

Слайд 10

Custom properties Core is a DOM processing engine. It is

Custom properties

Core is a DOM processing engine.
It is based on XML

tags and attributes.
XML/Valid XML/XHTML/Valid XHTML/HTML5/Legacy HTML5 processor.
Allows a fast processing of templates by intelligent caching of parsed files.
Not complex syntax.
Слайд 11

Syntax compare FreeMarker syntax: ${animal.name} ${animal.price} ApacheVelocity syntax: #foreach($mud in $mudsOnSpecial) #if($customer.hasPurchased($mud)) $flogger.getPromo($mud) #end #end

Syntax compare

FreeMarker syntax:


<#list animals as animal>
<#if animals.python.price !=
0>



${animal.name}${animal.price}

ApacheVelocity syntax:


#foreach($mud in $mudsOnSpecial)
#if($customer.hasPurchased($mud))



#end
#end
$flogger.getPromo($mud)

Слайд 12

Syntax compare Thymeleaf syntax: NAME PRICE IN STOCK Onions 2.41 yes

Syntax compare

Thymeleaf syntax:

: ${prods}">
NAME PRICE IN STOCK
Onions 2.41 yes

Слайд 13

Integration with Spring framework Spring application context: Html file template:

Integration with Spring framework

Spring application context:

/>
Html file template:

Слайд 14

Standard dialect Expressions: Variable Expressions: ${...} Selection Variable Expressions: *{...}

Standard dialect

Expressions:
Variable Expressions: ${...}
Selection Variable Expressions: *{...}
Message Expressions: #{...}
Link URL Expressions:

@{...}
If-then: (if) ? (then)
If-then-else: (if) ? (then) : (else)
Default: (value) ?: (defaultvalue)

Using with basic objects:
#ctx : the context object.
#vars: the context variables.
#locale : the context locale.
#httpServletRequest : (only in Web Contexts) the HttpServletRequest object.
#httpSession : (only in Web Contexts) the HttpSession object.

Слайд 15

Expression Utility Objects: #dates : utility methods for java.util.Date objects:

Expression Utility Objects:
#dates : utility methods for java.util.Date objects: formatting, component

extraction, etc.
#calendars : analogous to #dates , but for java.util.Calendar objects.
#numbers : utility methods for formatting numeric objects.
#strings : utility methods for String objects: contains, startsWith, prepending/appending, etc.
#objects : utility methods for objects in general.
#bools : utility methods for boolean evaluation.
#arrays : utility methods for arrays.
#lists : utility methods for lists.
#sets : utility methods for sets.
#maps : utility methods for maps.
#aggregates : utility methods for creating aggregates on arrays or collections.
#messages : utility methods for obtaining externalized messages inside variables expressions, in the same way as they would be obtained using #{…} syntax.
#ids : utility methods for dealing with id attributes that might be repeated.
Слайд 16

Dialect extension: xmlns:th="http://www.thymeleaf.org">

Dialect extension:

class="org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect"/>

xmlns:th="http://www.thymeleaf.org">
Слайд 17

Messages internationalization Application context: Class path:

Messages internationalization

Application context:

Class path:

Слайд 18

Fragmentation footer.html ... Footer copyrights ... Index.html ... ...

Fragmentation

footer.html
...

Footer

copyrights
...

Index.html
...



th:fragment="frag (onevar,twovar)">

...



Слайд 19

Usage Examples Object expression: Today is: 11 March 2016 Links

Usage Examples

Object expression:
Today is: 11 March 2016

Links usage:

href="details.html" th:href="@{/order/details(orderId=${o.id})}">view
view

Conditions usage:

...-
... ...
Слайд 20

Default expression: Some value Setting attribute: Forms: Iteration: Onions 2.41

Default expression:
Some value

Setting attribute:

th:attr="value=#{subscribe.submit}"/>

Forms:


Iteration:
Onions 2.41

Слайд 21

Local variable: Some Name . Set values to JavaScript: /*

Local variable:


Some Name.

Set values to JavaScript:

Switch:

User is an administrator

User is a manager


Слайд 22

Summary Advatages: Java template engine for XML, XHTML and HTML5.

Summary

Advatages:
Java template engine for XML, XHTML and HTML5.
Works both in web and non-web (offline) environments. No hard

dependency on the Servlet API.
Several template modes: XML, XHTML 1.0 and 1.1, HTML5:
Internationalization support.
Parsed template cache
Is extensible
Not very complex in usage
Many documentation

Disadvatages:
It's slowly than other templates.

Имя файла: Spring-teplates.-Thymeleaf-&amp;-spring-framework.pptx
Количество просмотров: 72
Количество скачиваний: 0