博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
分布式微服务云架构开发Web应用
阅读量:7172 次
发布时间:2019-06-29

本文共 1632 字,大约阅读时间需要 5 分钟。

hot3.png

举一个简单的例子,在快速入门工程的基础上,举一个简单的示例来通过Thymeleaf渲染一个页面。

@Controller  public class HelloController {        @RequestMapping("/")      public String index(ModelMap map) {          // 加入一个属性,用来在模板中读取          map.addAttribute("host", "http://blog.didispace.com");          // return模板文件的名称,对应src/main/resources/templates/index.html          return "index";        }    }
          

Hello World

如上页面,直接打开html页面展现Hello World,但是启动程序后,访问http://localhost:8080/,则是展示Controller中host的值:http://blog.didispace.com,做到了不破坏HTML自身内容的数据逻辑分离。

如有需要修改默认配置的时候,只需复制下面要修改的属性到application.properties中,并修改成需要的值,如修改模板文件的扩展名,修改默认的模板路径等。

# Enable template caching.  spring.thymeleaf.cache=true   # Check that the templates location exists.  spring.thymeleaf.check-template-location=true   # Content-Type value.  spring.thymeleaf.content-type=text/html   # Enable MVC Thymeleaf view resolution.  spring.thymeleaf.enabled=true   # Template encoding.  spring.thymeleaf.encoding=UTF-8   # Comma-separated list of view names that should be excluded from resolution.  spring.thymeleaf.excluded-view-names=   # Template mode to be applied to templates. See also StandardTemplateModeHandlers.  spring.thymeleaf.mode=HTML5   # Prefix that gets prepended to view names when building a URL.  spring.thymeleaf.prefix=classpath:/templates/   # Suffix that gets appended to view names when building a URL.  spring.thymeleaf.suffix=.html  spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain. spring.thymeleaf.view-names= # Comma-separated list of view names that can be resolved.

 

转载于:https://my.oschina.net/u/3873725/blog/1832904

你可能感兴趣的文章
AIX系统开启ftp服务
查看>>
linux 上拷贝文件到windows 上 文件出现锁的文件
查看>>
Xamarin iOS教程之编辑界面编写代码
查看>>
Construct Binary Tree from Preorder and Inorder Traversal
查看>>
写得好 git 提交信息
查看>>
Linux下获取线程TID的方法
查看>>
Redis和Memcache的区别分析(转)
查看>>
网络请求 http get post 一
查看>>
《计算机问题求解》总结——2014年CCF计算机课程改革导教班(2014.07.11)
查看>>
Google Chrome Plus——绿色便携多功能谷歌浏览器
查看>>
Instant Run
查看>>
浏览器中 for in 反射 对象成员 的差异
查看>>
关于Linux启动时挂载rootfs的几种方式
查看>>
vs2015 系统找不到指定的文件(异常来自HRESULT:0x80070002)问题的解决方法
查看>>
2018年总结
查看>>
34个漂亮的应用程序后台管理界面
查看>>
java JDK6的可变参数
查看>>
初入职场程序员的五大钻石法则
查看>>
Node.js学习笔记(一)概述
查看>>
split的3种方法
查看>>