这个3个电源哪个更苹果手表3值得购买吗

Thymeleaf html代码使用nginx与java代码分离 - 博客频道 - CSDN.NET
分类:thymeleaf
Thymeleaf html代码使用nginx与java代码分离
http://www.thymeleaf.org/apidocs/thymeleaf/3.0.3.RELEASE/
&org.springframework.boot&
&spring-boot-starter-thymeleaf&
方法1、JAVA代码
@Configuration
public class ThymeleafConfig{
@Autowired
private SpringTemplateEngine springTemplateE
String resourcesUrl = "http://127.0.0.1";
public void init(){
@PostConstruct
public void templateResolver() {
UrlTemplateResolver resolver = new UrlTemplateResolver();
resolver.setTemplateMode("HTML5");
resolver.setPrefix(resourcesUrl + "/resources/");
resolver.setSuffix(".html");
resolver.setCacheable(thymeleafCache);
resolver.setOrder(1);
resolver.setCharacterEncoding("UTF-8");
springTemplateEngine.setTemplateResolver(resolver);
方法2、配置文件
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=http://127.0.0.1/resources/
spring.thymeleaf.enabled=true
server_name
www.xxx.com
charset utf-8
location /resources/ {
root D:\workspaces
@Autowired
private SpringTemplateEngine springTemplateE
@RequestMapping(value = "/thymeleaf/cache/clear", method RequestMethod.GET)
@ResponseBody
public String initModifyCell(@RequestParam("name") String tmpName, Model model) throws Exception {
log.debug("handling clear tmp cache, tmpName={}", tmpName);
if ("ALL".equals(tmpName)) {
springTemplateEngine.clearTemplateCache();
springTemplateEngine.clearTemplateCacheFor(tmpName);
return "Thymeleaf template cache cleared successfully!";
package org.thymeleaf.
import java.net.MalformedURLE
import java.util.M
import java.util.regex.P
import org.thymeleaf.IEngineC
import org.thymeleaf.cache.ICacheEntryV
import org.thymeleaf.cache.NonCacheableCacheEntryV
import org.thymeleaf.templateresource.ITemplateR
import org.thymeleaf.templateresource.UrlTemplateR
Implementation of {@link ITemplateResolver} that extends {@link AbstractConfigurableTemplateResolver}
and creates {@link UrlTemplateResource} instances for template resources.
Note a class with this name existed since 1.0, but it was completely rewritten in Thymeleaf 3.0.
* Daniel Fern&ndez
public class UrlTemplateResolver extends AbstractConfigurableTemplateResolver {
private static final Pattern JSESSIONID_PATTERN = pile("(.*?);jsessionid(.*?)");
public UrlTemplateResolver() {
protected ITemplateResource computeTemplateResource(
final IEngineConfiguration configuration, final String ownerTemplate, final String template, final String resourceName, final String characterEncoding, final Map&String, Object& templateResolutionAttributes) {
return new UrlTemplateResource(resourceName, characterEncoding);
} catch (final MalformedURLException ignored) {
return null;
protected ICacheEntryValidity computeValidity(final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Map&String, Object& templateResolutionAttributes) {
if (JSESSIONID_PATTERN.matcher(template.toLowerCase()).matches()) {
return NonCacheableCacheEntryValidity.INSTANCE;
return super.computeValidity(configuration, ownerTemplate, template, templateResolutionAttributes);
排名:千里之外
(11)(1)(1)(1)(1)(1)(1)(1)(0)(1)前台form表单
th:object即为你的javabean的名字,后台使用时也必须是这个名字。th:field即为属性的名字。
后台简单接收代码。
注明:本文章属于转载,仅供行业人员学习交流使用,文章版权属于原创作者,在此向原创者致敬,感谢原创作者为大家学习交流提供精品内容。
站方声明:IThao123是为广大互联网从业者免费提供学习交流的平台,如果侵犯了原创著作权,请联系站方删除,给你带来不便,深表歉意。当前位置: >
【java技术】Spring集成Thymeleaf模板引擎
作者:简单生活 来源:本站 发表时间: 09:04:33&查看:次
Spring集成Thymeleaf模板引擎
常用的模版引擎
velocity &&&&&默认模板的后缀vm
freemarker &&&默认模板的后缀ftl
thymeleaf &&&&默认模板的后缀html
使用模版引擎好处
可以有效将美工和程序员结合起来,
美工能够在浏览器中查看静态效果,
程序员可以在应用服务器查看带数据的效果
thymeleaf是一个支持html原型的自然引擎,
在html标签增加额外的属性来达到模板+数据的展示方式,
由于浏览器解释html时,忽略未定义的标签属性,
故thymeleaf的模板可以静态运行
第一次jsp执行流程:jsp先转译为java文件,然后编译为class文件
第2-n次jsp(没有修改)执行流程:直接访问class文件
而模板技术怎样输出数据:
数据+模板(html文件,vm文件,ftl文件)=输出内容
故第一次访问模版技术性能要比jsp高些,而thymeleaf比其他2个性能还好些
Spring集成Thymeleaf
配置TemplateEngine
配置Spring中的ViewResolver
IndexController
渲染模板前,ThymeleafViewResolver会自动把当前的Model加入到模板的Context中,从而在index.html显示出数据
表单和Command对象之间的转换
Command对象是用来在Spring MVC中绑定表单与后端对象,
Thymeleaf提供的th:object属性可以用来指定Command对象:
指定th:object属性后,各个中还需要指定th:field,这与后端绑定对象的字段名要一致。
在IndexController中的方法如下:
上一篇:下一篇:
新闻分类 News Nav
推荐新闻 News
联系我们 Contact Us
全国统一服务热线
我们的邮箱
版权所有:华兴教育在上篇文章中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thymeleaf的使用。thymeleaf
是新一代的模板引擎,在spring4.0中推荐使用thymeleaf来做前端模版引擎。
前几篇文章地址:
作者:纯洁的微笑&
thymeleaf介绍
简单说, Thymeleaf 是一个跟 Velocity、FreeMarker 类似的模板引擎,它可以完全替代 JSP 。相较与其他的模板引擎,它有如下三个极吸引人的特点:
1.Thymeleaf 在有网络和无网络的环境下皆可运行,即它可以让美工在浏览器查看页面的静态效果,也可以让程序员在服务器查看带数据的动态页面效果。这是由于它支持 html 原型,然后在 html 标签里增加额外的属性来达到模板+数据的展示方式。浏览器解释 html 时会忽略未定义的标签属性,所以 thymeleaf 的模板可以静态地运行;当有数据返回到页面时,Thymeleaf 标签会动态地替换掉静态内容,使页面动态显示。
2.Thymeleaf 开箱即用的特性。它提供标准和标准两种方言,可以直接套用模板实现JSTL、 OGNL表达式效果,避免每天套模板、该jstl、改标签的困扰。同时开发人员也可以扩展和创建自定义的方言。
3.Thymeleaf 提供spring标准方言和一个与 SpringMVC 完美集成的可选模块,可以快速的实现表单绑定、属性编辑器、国际化等功能。
标准表达式语法
它们分为四类:
1.变量表达式2.选择或星号表达式3.文字国际化表达式4.URL表达式
变量表达式
变量表达式即OGNL表达式或Spring EL表达式(在Spring术语中也叫model attributes)。如下所示:&
${session.user.name}
它们将以HTML标签的一个属性来表示:
&span th:text=&${book.author.name}&&
&li th:each=&book : ${books}&&
选择(星号)表达式
选择表达式很像变量表达式,不过它们用一个预先选择的对象来代替上下文变量容器(map)来执行,如下:&
*{customer.name}
被指定的object由th:object属性定义:
&div th:object=&${book}&&
&span th:text=&*{title}&&...&/span&
1234512345
文字国际化表达式
文字国际化表达式允许我们从一个外部文件获取区域文字信息(.properties),用Key索引Value,还可以提供一组参数(可选).
#{main.title}
#{message.entrycreated(${entryId})}
可以在模板文件中找到这样的表达式代码:
&th th:text=&#{header.address.city}&&...&/th&
&th th:text=&#{header.address.country}&&...&/th&
123456123456
URL表达式指的是把一个有用的上下文或回话信息添加到URL,这个过程经常被叫做URL重写。&
@{/order/list}&
URL还可以设置参数:&
@{/order/details(id=${orderId})}&
相对路径:&
@{../documents/report}
让我们看这些表达式:
th:action=&@{/createOrder}&&
href=&main.html& th:href=&@{/main}&&1212
变量表达式和星号表达有什么区别吗?
如果不考虑上下文的情况下,两者没有区别;星号语法评估在选定对象上表达,而不是整个上下文&
什么是选定对象?就是父标签的值,如下:
th:object=&${session.user}&&
th:text=&*{firstName}&&Sebastian&.&
th:text=&*{lastName}&&Pepper&.&
&Nationality:
th:text=&*{nationality}&&Saturn&.&
&1234512345
这是完全等价于:
th:object=&${session.user}&&
th:text=&${session.user.firstName}&&Sebastian&.&
th:text=&${session.user.lastName}&&Pepper&.&
&Nationality:
th:text=&${session.user.nationality}&&Saturn&.&
&1234512345
当然,美元符号和星号语法可以混合使用:
th:object=&${session.user}&&
th:text=&*{firstName}&&Sebastian&.&
th:text=&${session.user.lastName}&&Pepper&.&
&Nationality:
th:text=&*{nationality}&&Saturn&.&
&1234512345
表达式支持的语法
字面(Literals)
文本文字(Text literals):&'one text', 'Another one!',…数字文本(Number literals):&0, 34, 3.0, 12.3,…布尔文本(Boolean literals):&true, false空(Null literal):&null文字标记(Literal tokens):&one, sometext, main,…
文本操作(Text operations)
字符串连接(String concatenation):&+文本替换(Literal substitutions):&|The name is ${name}|
算术运算(Arithmetic operations)
二元运算符(Binary operators):&+, -, *, /, %减号(单目运算符)Minus sign (unary operator):&-
布尔操作(Boolean operations)
二元运算符(Binary operators):and, or布尔否定(一元运算符)Boolean negation (unary operator):!, not
比较和等价(Comparisons and equality)
比较(Comparators):&&, &, &=, &= (gt, lt, ge, le)等值运算符(Equality operators):==, != (eq, ne)
条件运算符(Conditional operators)
If-then:&(if) ? (then)If-then-else:&(if) ? (then) : (else)Default: (value) ?:&(defaultvalue)
所有这些特征可以被组合并嵌套:
'User is of type ' + (${user.isAdmin()} ? 'Administrator' : (${user.type} ?: 'Unknown'))11
常用th标签都有那些?
&input th:id=&'xxx' + ${collect.id}&/&
&p th:text=&${collect.description}&&description&/p&
支持html的文本替换
&p th:utext=&${htmlcontent}&&conten&/p&
&div th:object=&${session.user}&&
属性赋值
&input th:value=&${user.name}& /&
变量赋值运算
&div th:with=&isEven=${prodStat.count}%2==0&&&/div&
th:style=&'display:' + @{(${sitrue} ? 'none' : 'inline-block')} + ''&
th:onclick
th:onclick=&'getCollect()'&
属性赋值
tr th:each=&user,userStat:${users}&&
&a th:if=&${userId == collect.userId}& &
和th:if判断相反
&a th:href=&@{/login}& th:unless=${session.user != null}&Login&/a&
&a th:href=&@{/login}& th:unless=${session.user != null}&Login&/a& /&
多路选择 配合th:case 使用
&div th:switch=&${user.role}&&
th:switch的一个分支
&p th:case=&'admin'&&User is an administrator&/p&
th:fragment
布局标签,定义一个代码片段,方便其它地方引用
&div th:fragment=&alert&&
th:include
布局标签,替换内容到引入的文件
&head th:include=&layout :: htmlhead& th:with=&title='xx'&&&/head& /&
th:replace
布局标签,替换整个标签到引入的文件
&div th:replace=&fragments/header :: title&&&/div&
th:selected
selected选择框 选中
th:selected=&(${xxx.id} == ${configObj.dd})&
图片类地址引入
&img class=&img-responsive& alt=&App Logo& th:src=&@{/img/logo.png}& /&
定义js脚本可以使用变量
&script type=&text/javascript& th:inline=&javascript&&
表单提交的地址
&form action=&subscribe.html& th:action=&@{/subscribe}&&
删除某个属性
&tr th:remove=&all&& 1.all:删除包含标签和所有的孩子。
设置标签属性,多个属性可以用逗号分隔
比如&th:attr=&src=@{/image/aa.jpg},title=#{logo}&,此标签不太优雅,一般用的比较少。
还有非常多的标签,这里只列出最常用的几个,由于一个标签内可以包含多个th:x属性,其生效的优先级顺序为:&
include,each,if/unless/switch/case,with,attr/attrprepend/attrappend,value/href,src ,etc,text/utext,fragment,remove。
几种常用的使用方法
1、赋值、字符串拼接
th:text=&${collect.description}&&description&
th:text=&'Welcome to our application, ' + ${user.name} + '!'&&1212
字符串拼接还有另外一种简洁的写法
&span th:text=&|Welcome to our application, ${user.name}!|&&11
2、条件判断 If/Unless
Thymeleaf中使用th:if和th:unless属性进行条件判断,下面的例子中,&a&标签只有在th:if中条件成立时才显示:
th:if=&${myself=='yes'}& & & &
th:unless=${session.user != null} th:href=&@{/login}& &Login&1212
th:unless于th:if恰好相反,只有表达式中的条件不成立,才会显示其内容。
也可以使用&(if) ? (then) : (else)&这种语法来判断显示的内容
3、for 循环
th:each=&collect,iterStat : ${collects}&&
scope=&row& th:text=&${collect.id}&&1&
th:src=&${collect.webLogo}&/&
th:text=&${collect.url}&&Mark&
th:text=&${collect.title}&&Otto&
th:text=&${collect.description}&&@mdo&
th:text=&${terStat.index}&&index&
&1234567891012345678910
iterStat称作状态变量,属性有:
index:当前迭代对象的index(从0开始计算)count: 当前迭代对象的index(从1开始计算)size:被迭代对象的大小current:当前迭代变量even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)first:布尔值,当前循环是否是第一个last:布尔值,当前循环是否是最后一个
URL在Web应用模板中占据着十分重要的地位,…}来处理的。&
如果需要Thymeleaf对URL进行渲染,那么务必使用th:href,th:src等属性,下面是一个例子
th:href=&@{/standard/{type}(type=${type})}&&view&
href=&details.html& th:href=&@{/order/{orderId}/details(orderId=${o.id})}&&view&1234512345
th:style=&'background:url(' + @{/&path-to-image&} + ');'&&&11
根据属性值改变背景
&div class=&media-object resource-card-image&
th:style=&'background:url(' + @{(${collect.webLogo}=='' ? 'img/favicon.png' : ${collect.webLogo})} + ')'& &&/div&11
几点说明:
上例中URL最后的(orderId=${o.id})&表示将括号内的内容作为URL参数处理,该语法避免使用字符串拼接,大大提高了可读性@{...}表达式中可以通过{orderId}访问Context中的orderId变量@{/order}是Context相关的相对路径,在渲染时会自动添加上当前Web应用的Context名字,假设context名字为app,那么结果应该是/app/order
内联文本:[[…]]内联文本的表示方式,使用时,必须先用th:inline=”text//none”激活,th:inline可以在父级标签内使用,甚至作为body的标签。内联文本尽管比th:text的代码少,不利于原型显示。
&script th:inline=&javascript&&
/*&![CDATA[*/
var username = /*[[${sesion.user.name}]]*/ 'Sebastian';
var size = /*[[${size}]]*/ 0;
&/script&1234567812345678
js附加代码:
var msg = 'This is a working application';
+]*/123123
js移除代码:
var msg = 'This is a non-working template';
6、内嵌变量
为了模板更加易用,Thymeleaf还提供了一系列Utility对象(内置于Context中),可以通过#直接访问:
dates :&java.util.Date的功能方法类。calendars :&类似#dates,面向java.util.Calendarnumbers :&格式化数字的功能方法类strings :&字符串对象的功能类,contains,startWiths,prepending/appending等等。objects:&对objects的功能类操作。bools:&对布尔值求值的功能方法。arrays:对数组的功能类方法。lists:&对lists功能类方法setsmaps&
下面用一段代码来举例一些常用的方法:
* Format date with the specified pattern
* Also works with arrays, lists or sets
* Create a date (java.util.Date) object for the current date and time
* Create a date (java.util.Date) object for the current date (time set to 00:00)
${123456789101112131415161718123456789101112131415161718
* Check whether a String is empty (or null). Performs a trim() operation before check
* Also works with arrays, lists or sets
${#strings.isEmpty(name)}
${#strings.arrayIsEmpty(nameArr)}
${#strings.listIsEmpty(nameList)}
${#strings.setIsEmpty(nameSet)}
* Check whether a String starts or ends with a fragment
* Also works with arrays, lists or sets
${#strings.startsWith(name,'Don')}
// also array*, list* and set*
${#strings.endsWith(name,endingFragment)}
// also array*, list* and set*
* Compute length
* Also works with arrays, lists or sets
${#strings.length(str)}
* Null-safe comparison and concatenation
${#strings.equals(str)}
${#strings.equalsIgnoreCase(str)}
${#strings.concat(str)}
${#strings.concatReplaceNulls(str)}
${#strings.randomAlphanumeric(count)}1234567891011121314151617181920212223242526272829303132333412345678910111213141516171819202122232425262728293031323334
使用thymeleaf布局
使用thymeleaf布局非常的方便
定义代码片段
th:fragment=&copy&&
在页面任何地方引入:
th:include=&footer :: copy&&&
th:replace=&footer :: copy&&&
th:include 和 th:replace区别,include只是加载,replace是替换
返回的HTML如下:
& & 2016 &
下面是一个常用的后台页面布局,将整个页面分为头部,尾部、菜单栏、隐藏栏,点击菜单只改变content区域的页面
&body class=&layout-fixed&&
&div th:fragment=&navbar&
class=&wrapper&
role=&navigation&&
&div th:replace=&fragments/header :: header&&Header&/div&
&div th:replace=&fragments/left :: left&&left&/div&
&div th:replace=&fragments/sidebar :: sidebar&&sidebar&/div&
&div layout:fragment=&content& id=&content& &&/div&
&div th:replace=&fragments/footer :: footer&&footer&/div&
&/body&123456789123456789
任何页面想使用这样的布局值只需要替换中见的 content模块即可
&html xmlns:th=&http://www.thymeleaf.org& layout:decorator=&layout&&
&section layout:fragment=&content&&
...12341234
也可以在引用模版的时候传参
th:include=&layout :: htmlhead& th:with=&title='Hello'&&&11
layout 是文件地址,如果有文件夹可以这样写 fileName/layout:htmlhead&
htmlhead 是指定义的代码片段 如&th:fragment=&copy&
这里有一个开源项目几乎使用了这里介绍的所有标签和布局,大家可以参考:&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:13124次
排名:千里之外
原创:27篇
转载:11篇
(2)(5)(10)(11)(11)我们提供一个Java使用Thymeleaf的简单示例。Thymeleaf是一个模板引擎可以处理XML,XHTML、HTML5。Thymeleaf利用最少的IO操作来获得更快的速度,使用thymeleaf模板引擎加快了前后端开发工作的并行运作。Thymeleaf还提供了国际化。Thymeleaf提供了最基础的两个编程API:ServletContextTemplateResolver 和TemplateEngine。Servletcontexttemplateresolver负责解析模板、Templateengine使用templateengine process()方法处理模板数据。模板引擎表达式可以从properties文件和WebContext获取属性值从而展示到页面。需要注意的是:属性文件、模板文件必须同名且位于同一目录(编译后)。
使用servlet3.0注解报会在访问时报404错误,解决方案如下web.xml文件头如下配置:
version="3.0" xmlns="/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="/xml/ns/javaee
/xml/ns/javaee/web-app_3_0.xsd"&
Java+Thymeleaf示例程序的准备工作
(本文章分享在CSDN平台,更多精彩请阅读 东陆之滇的csdn博客: ,如在其他平台看到此文可能会出现内容不完整的现象,请移至查看原文)
示例程序的目录结构
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&
&org.byron4j&
&java2Thymeleaf&
&1.0.0-SNAPSHOT&
&java2Thymeleaf&
&http://blog.csdn.net/zixiao217/article/details/&
&javax.servlet&
&javax.servlet-api&
&provided&
&org.thymeleaf&
&thymeleaf-spring4&
&2.1.5.RELEASE&
&thymeDemo&
&org.apache.maven.plugins&
&maven-compiler-plugin&
使用th:text外化文本
打开我们的模板文件WEB-INF\templates\welcome.html,如果我们直接访问该html文件,则会显示”Welcome Offline”,当我们通过服务启动之后访问url则显示从后台获得的属性值。
注意:在模板文件中需要声明thymeleaf的文档类型、xml命名空间,WEB-INF\templates\welcome.html :
&!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"&
xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"&
&Thymeleaf-Java Demo&
http-equiv="Content-Type" content="text/charset=UTF8" /&
th:text="#{welcome.msg}"&喂,掉线了丿_|&
th:text="${currentDate}"& 00:00:00&&
th:text: 该属性用来计算表达式的值,并将结果展示为标签的内容
#{…}: 从属性文件获得该属性的值。 表达式#{welcome.msg} 会尝试获得属性文件中key为welcome.msg的value。
${…}: OGNL表达式 会获取在org.thymeleaf.context.WebContext中设置的值。在这个Demo中表达式${currentDate} 将会获取在WebContext中设置的currentDate 属性值。
ServletContextTemplateResolver 解析模板和TemplateEngine.process()处理模板
ThymeleafAppUtil.java
package org.byron4j.java2T
import org.thymeleaf.TemplateE
import org.thymeleaf.templateresolver.ServletContextTemplateR
Thymeleaf模板引擎和解析器
public class ThymeleafAppUtil {
private static TemplateEngine templateE
* static代码块,加载初始模板设置:/WEB-INF/templates/**.html文件
ServletContextTemplateResolver templateResolver =
new ServletContextTemplateResolver();
templateResolver.setTemplateMode("XHTML");
templateResolver.setPrefix("/WEB-INF/templates/");
templateResolver.setSuffix(".html");
templateResolver.setCacheTTLMs(3600000L);
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
public static TemplateEngine getTemplateEngine() {
return templateE
ServletContextTemplateResolver: 负责解析Thymeleaf模板。我们需要设置模板模式、模板文件的前缀、后缀等。
TemplateEngine: 处理thymeleaf模板。
属性文件、模板文件必须同名且放在一个目录中(项目编译后)
WEB-INF\templates\welcome_en.properties
welcome.msg=Welcome to Thymeleaf World!
WEB-INF\templates\welcome_zh.properties
welcome.msg=欢迎使用 Thymeleaf!
WelcomeServlet.java
package org.byron4j.java2T
import java.io.IOE
import javax.servlet.annotation.WebS
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
使用servlet3注解,注册一个servlet,并在容器启动时加载
@WebServlet(urlPatterns = "/welcome", loadOnStartup = 1)
public class WelcomeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
doGet(request,response);
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
response.setContentType("text/charset=UTF-8");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
WelcomeApplication application = new WelcomeApplication();
application.process(request, response);
WelcomeApplication.java
package org.byron4j.java2T
import java.io.IOE
import java.text.SimpleDateF
import java.util.D
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import org.thymeleaf.context.WebC
public class WelcomeApplication {
public void process(HttpServletRequest request, HttpServletResponse response)
throws IOException {
WebContext ctx = new WebContext(request, response, request.getServletContext(),
request.getLocale());
ctx.setVariable("currentDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
* 使用Thymeleaf引擎加载模板文件welcome.html
ThymeleafAppUtil.getTemplateEngine().process("welcome", ctx, response.getWriter());
声明使用了servlet3,eclipse默认生成的web.xml使用的是servlet2.3、2.5,我们需要手动指定为servlet3,运用servlet3.0注解报会在访问时报404错误。
&?xml version="1.0" encoding="UTF-8"?&
version="3.0" xmlns="/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="/xml/ns/javaee
/xml/ns/javaee/web-app_3_0.xsd"&
&Archetype Created Web Application&
完整的Demo Maven工程代码
演示项目源码下载
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:64192次
积分:1777
积分:1777
排名:千里之外
原创:84篇
转载:14篇
译文:26篇
阅读:4482
(6)(6)(5)(1)(3)(7)(28)(43)(6)(1)(17)(2)(1)

我要回帖

更多关于 苹果手表3值得购买吗 的文章

 

随机推荐