分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

分布式微服务云架构开发Web应用

发布时间:2023-09-06 02:00责任编辑:苏小强关键词:Web

举一个简单的例子,在快速入门工程的基础上,举一个简单的示例来通过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"; ???????} ???} ?
<!DOCTYPE html> ?<html> ?<head lang="en"> ?????<meta charset="UTF-8" /> ?????<title></title> ?</head> ?<body> ?<h1 th:text="${host}">Hello World</h1> ?</body> ?</html> ?

如上页面,直接打开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. ?

分布式微服务云架构开发Web应用

原文地址:https://www.cnblogs.com/xiaopaodeboke/p/9204283.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved