当前位置: 首页 > news >正文

aspcms网站打不开免费店铺logo

aspcms网站打不开,免费店铺logo,wordpress多站点 文章导入,2012r2做网站Thymeleaf介绍Thymeleaf#xff0c;是一个XML/XHTML/HTML模板引擎#xff0c;开源的java库#xff0c;可以用于SpingMVC项目中#xff0c;用于代替JSP、FreeMarker或者其他的模板引擎#xff1b;页面与数据分离#xff0c;提高了开发效率#xff0c;让代码重用更容易。S…Thymeleaf介绍Thymeleaf是一个XML/XHTML/HTML模板引擎开源的java库可以用于SpingMVC项目中用于代替JSP、FreeMarker或者其他的模板引擎页面与数据分离提高了开发效率让代码重用更容易。Springboot集成Thymeleaf文章示例环境配置信息jdk版本:1.8开发工具Intellij iDEA 2020.1springboot:2.3.9.RELEASE依赖引入dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId /dependency dependencygroupIdognl/groupIdartifactIdognl/artifactIdversion3.1.26/version /dependency配置文件spring.thymeleaf.cachefalse spring.thymeleaf.suffix.html spring.thymeleaf.prefixclasspath:/templates/ spring.thymeleaf.servlet.content-typetext/html spring.thymeleaf.encodingutf-8 spring.messages.basenamei18n/messages集成示例thymeleaf的用法其实和jsp、freemarker差不多下面用一个示例实际看一下thymeleaf是怎么使用的1、定义一个ExampleController类注意这里使用Controller注解标记ExampleController不要使用RestController2、controller层具体处理请求的方法内增加一个形参org.springframework.ui.Model用于携带后台的处理数据3、返回值的“index”表示classpath下templates中模板名称是index后缀是.html的模板4、contoller层处理完后携带后台处理数据到达视图层进行数据的渲染。Controller RequestMapping(/example) public class ExampleController {GetMapping(/index)public String index(Model model) {model.addAttribute(userName, fanfu);model.addAttribute(msg, thymeleaf模板内容);return index;} }这里注意一下通过xmlns:thhttp://www.thymeleaf.org引入了thymeleaf命名空间th:text用于处理html标签体的文本内容但是html5不允许使用th:*这些非标准属性的因此可以切换到thymeleaf的data-th-*方法来替换th:*方法因此可以这么理解th:*和data-th-*的用法是等效的为了遵循标准的用法这篇文章的所有示例都采用data-th-*的写法。!DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title测试/title /head bodydiv你好span data-th-text${userName}/span/divdiv这是一个span data-th-text${msg}/span 。/div /body /htmlThymeleaf语法表达式thymeleaf内置了5种标准表达式如下1、${...}变量表达式取出上下文环境中变量的值p data-th-text${username}/p2、*{...}选择变量表达式取选择的对象的属性值div data-th-object${formObj}p data-th-text*{title}/pp data-th-text*{creator}/p /div3、#{...}消息表达式使用文字消息的国际化p data-th-text#{welcome.message}/p p data-th-text#{welcome.user.message(${formObj.creator})}/p4、{...}链接表达式用于表示各种超链接地址 p data-th-text{http://localhost:8080/example/index(creator${formObj.creator},status1)}/p a data-th-href{url} target_blank超链接/a5、~{...}片段表达式引用一段公共的代码片段如下“example”表示另外一个模板名字里面是一些通用代码片段可以使用这种方式引入到当前模板中p data-th-text~{example}/p遍历p data-th-eachstudent:${students} data-th-text${student.name}/p条件判断条件判断语句有三种分别是th:if、th:unless、th:switchth:if如果表达式内容为真则显示内容p data-th-if${userName!null}如果username不是null,我就会显示/pth:unless如果表达式内容为假则显示内容p data-th-unless${userNamenull}如果username不是null,我就会显示/pth:switch为多路选择语句需要搭配th:case来使用; div data-th-switch${userName}p data-th-casefanfu凡夫贬夫你好/pp data-th-casetest这是一个test/p /divThymeleaf应用场景Thymeleaf可以替代JSP来进行动态网页的开发但是在前后端分离、前端组件更加丰富多元化的今天依然采用JSP的模式用Thymeleaf来替代JSP进行动态网页的开发未免有些落后了因此Thymeleaf就没有用武之地吗当然不。Thymeleaf是模板引擎不仅可以处理html模板还可以处理xml、CSS等其他一些格式的模板文件。例如输出一些有样式的制式文本如通知公告、申请书、建议书等。下面是一个具体的示例student.html是一个学生成绩展示的模板但是学生会有很多成绩也不一样但是如果需要用一个制式的格式来展示这些数据可以这么做1、先拿到学生的成绩数据2、然后用编程式的方法使用thymeleaf模板引擎根据模板生成静态的带有样式且加载好数据的html网页代码3、通常成绩、通知这类信息一旦形成基本上是不会改了因此拿到已经加载数据的html网页内容就可以直接渲染显示了Test public void test() throws IOException {//测试数据ListStudent students this.students();String staticDir ResourceUtils.getFile(classpath:static\\).getPath() File.separator;String targetFilePathstaticDir/student-data.html;//thymeleaf引擎上下文环境Context contextnew Context();//在thymeleaf引擎上下文环境中装载模板上要渲染的数据context.setVariable(students,students);File file new File(targetFilePath);if (!file.exists()) {file.delete();}//定义thymeleaf模板打印输出流PrintWriter printWriternew PrintWriter(file);//定义thymeleaf模板解析器FileTemplateResolver fileTemplateResolver new FileTemplateResolver();//thymeleaf模板解析器解析内容的后缀fileTemplateResolver.setSuffix(.html);//thymeleaf模板解析器解析内容的前缀String tempDir ResourceUtils.getFile(classpath:templates\\).getPath()File.separator;fileTemplateResolver.setPrefix(tempDir);//定义//thymeleaf模板引擎TemplateEngine templateEngine new TemplateEngine();//装载thymeleaf模板解析器templateEngine.setTemplateResolver(fileTemplateResolver);//执行thymeleaf模板引擎的模板解析能力有三个参数分别是模板名字不包括后缀和前缀、上下文环境、打印输出流templateEngine.process(student,context,printWriter); } public ListStudent students() {ListStudent students new ArrayList();for (int i 0; i 10; i) {Student student new Student();student.setName(张三 i);student.setScore(98);students.add(student);}return students; }!DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8/title学生信息/title /head body divpspan data-th-text姓名/span-----span data-th-text成绩/span/pp data-th-eachstudent:${students}span data-th-text${student.name}/span-----span data-th-text${student.score}/span/p /div /body /html
http://www.w-s-a.com/news/898566/

相关文章:

  • 学校网站如何做广州商城型网站建设
  • 微网站建设哪家便宜易优建站系统
  • 推荐做木工的视频网站毕业设计做的网站抄袭
  • 网站导航页面制作wordpress调用文章阅读量
  • app小程序网站开发品牌购物网站十大排名
  • 用wordpress做购物网站龙岩品牌设计
  • 网站开发是指wordpress系统在线升级
  • 网站建设运营的灵魂是什么意思页面跳转中
  • 家政服务网站源码重庆建网站企业有哪些
  • 怎样分析一个网站做的好坏重庆长寿网站设计公司哪家专业
  • 百度助手app下载苏州seo关键词优化排名
  • 17网站一起做 佛山诸城网站建设多少钱
  • 郑州网站建设培训学校泉州做网站设计公司
  • 西峡做网站深圳建筑工务署官网
  • 单县网站惠州seo计费
  • 万网网站建设 优帮云怎样用记事本做网站
  • 注册域名后网站建设百度指数的功能
  • 怎么做伪静态网站山西网站建设设计
  • 做小型企业网站多少钱衡阳市建设局网站
  • 金华专业网站建设公司网站建设空间和服务器方式
  • 自己做的网站在浏览器上显示不安全吗wordpress revolution slider
  • 西安网站建设推广优化搜索引擎营销
  • 互联网站备案管理工作方案 工信部注册深圳公司需要什么条件
  • 网站网站服务器网站建设 物流
  • 国外开发网站手机网站建设制作
  • 怎么把自己做的网站传网上青岛工程建设监理公司网站
  • 网站301跳转效果商丘网站公司
  • 公司网站建设西安网站的架构与建设
  • 食品科技学校网站模板花溪村镇建设银行网站
  • 图片渐隐 网站头部flash地方志网站建设自查报告