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

网站制作公司代理企业营销策划包括哪些内容

网站制作公司代理,企业营销策划包括哪些内容,wordpress 安装百度统计,网站后台管理系统源码目录 Thymeleaf 模板引擎 1. 第一个例子 2. 表达式 ①标准变量表达式 ②选择变量表达式#xff08;星号变量表达式#xff09; ③链接表达式#xff08;URL表达式#xff09; 3. Thymeleaf的属性 ①th:action ②th:method ③th:href ④th:src ⑤th:text ⑥th:…目录 Thymeleaf 模板引擎 1. 第一个例子 2. 表达式 ①标准变量表达式 ②选择变量表达式星号变量表达式 ③链接表达式URL表达式 3. Thymeleaf的属性 ①th:action ②th:method ③th:href ④th:src ⑤th:text ⑥th:style ⑦th:each 重点 ⑧条件判断 if-unless ⑨switch-case 判断语句 ⑩th:inline内联 内联 text 内联javascript 4. 字面量 5.字符串连接重要 6. 运算符 7. Thymeleaf内置对象 8. Thymeleaf内置工具类对象 9.自定义模板内容复用 模板语法 插入模板和包含模板 整个html页面作为模板插入  图书推荐《巧用ChatGPT轻松玩转新媒体运营》 Thymeleaf 模板引擎 Thymeleaf 是一个流行的模板引擎该模板引擎采用 Java 语言开发。         模板引擎是一个技术名词是跨领域跨平台的概念在 Java 语言体系下有模板引擎在 C#、PHP 语言体系下也有模板引擎甚至在 JavaScript 中也会用到模板引擎技术Java 生态下 的模板引擎有 Thymeleaf 、Freemaker、Velocity、Beetl国产 等。         Thymeleaf 对网络环境不存在严格的要求既能用于 Web 环境下也能用于非 Web 环境 下。在非 Web 环境下他能直接显示模板上的静态数据在 Web 环境下它能像 Jsp 一样从 后台接收数据并替换掉模板上的静态数据。它是基于 HTML 的以 HTML 标签为载体 Thymeleaf 要寄托在 HTML 标签下实现。         Spring Boot 集成了 Thymeleaf 模板技术并且 Spring Boot 官方也推荐使用 Thymeleaf 来 替代 JSP 技术Thymeleaf 是另外的一种模板技术它本身并不属于 Spring BootSpring Boot 只是很好地集成这种模板技术作为前端页面的数据展示在过去的 Java Web 开发中我们 往往会选择使用 Jsp 去完成页面的动态渲染但是 jsp 需要翻译编译运行效率低 。 Thymeleaf 的官方网站Thymeleaf Thymeleaf 官方手册Tutorial: Using Thymeleaf 1. 第一个例子 ①创建项目引入web和thymeleaf依赖 ②pom.xml主要依赖 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.7.15/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.zl/groupIdartifactIdspringboot-myredis/artifactIdversion0.0.1-SNAPSHOT/versionnamespringboot-myredis/namedescriptionspringboot-myredis/descriptionpropertiesjava.version1.8/java.version/propertiesdependencies!--模板依赖--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-thymeleaf/artifactId/dependency!--web依赖--dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-configuration-processor/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build/project③Controller编写存放数据 package com.zl.controller;import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping;import javax.servlet.http.HttpServletRequest;Controller public class HelloThymeleafController {GetMapping(/hello)public String helloThymeleafController(HttpServletRequest request){// 添加数据到request域当中模板引擎可以从request域当中获取request.setAttribute(data,第一个Thymeleaf数据);// 返回到视图(html)return hello;} }④视图hello.html取出数据放到templates中 !DOCTYPE html !--加入xmlns命名空间-- html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head body !--取出数据-- h1 th:text${data}/h1想显示的数据 /body /html ⑤进行访问 模板引擎的常用配置 思考为什么controller返回一个字符串就可以直接找到templates下的对应html呢这些和模板引擎的默认设置是有关的 application.properties配置 注在开发阶段只需要把cache设置为false即可其它都是默认选项不需要修改 #开发阶段设置为 false 上线后设置为 true默认是true走缓存 spring.thymeleaf.cachefalse # 设置模版文件的路径前缀默认就是classpath:/templates/ spring.thymeleaf.prefixclasspath:/templates/ # 设置后缀,默认就是 .html spring.thymeleaf.suffix.html #编码方式默认就是UTF-8所以中文不会乱码 spring.thymeleaf.encodingUTF-8 #模板的类型默认是HTML模板是html文件 spring.thymeleaf.modeHTML2. 表达式 表达式是在页面获取数据的一种 thymeleaf 语法。类似 ${key} 。 ①标准变量表达式 注意th:text${key} 是 Thymeleaf 的一个属性用于文本的显示。 语法: ${key} 。 说明标准变量表达式用于访问容器tomcat上下文环境中的变量功能和 EL 中的 ${} 相 同。Thymeleaf 中的变量表达式使用 ${变量名} 的方式获取 Controller 中 model 其中的数据。 也就是 request 作用域中的数据。 准备Student数据 package com.zl.pojo;public class Student {private String name;private Integer age;public Student(String name, Integer age) {this.name name;this.age age;}public Student() {}Overridepublic String toString() {return Student{ name name \ , age age };}public String getName() {return name;}public void setName(String name) {this.name name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age age;} }欢迎页面index.html放入静态资源static下不走模板引擎 !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body a hrefthymeleaf/expression1标准变量表达式/a /body /html application.properties #配置端口号 server.port8082 #开发阶段设置为 false 上线后设置为 true默认是true走缓存 spring.thymeleaf.cachefalse controller存放数据跳转到expression1 package com.zl.controller;import com.zl.pojo.Student; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;Controller RequestMapping(/thymeleaf) public class ThymeleafExpressionController {GetMapping(/expression1)public String expression1(Model model){// 添加数据model.addAttribute(student,new Student(Jack,18)); // 跳转到视图 return expression1;} }expression1.html接收数据 注${student.getName()}也能获取到值底层实际上就是调用对应的Get方法 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleexpression1/title /head body h1 th:text${student.name}/h1 h1 th:text${student.age}/h1 !--调用g对应的get方法也可以-- h1 th:text${student.getAge()}/h1 /body /html 执行结果 ②选择变量表达式星号变量表达式 语法*{key} 。 说明不能单独使用需要配和 th:object 一起使用。选择变量表达式也叫星号变量表达式使用 th:object 属性来绑定对象选择表达式首先使用 th:object 来绑定后台传来的对象然后使用 * 来代表这个对象后面 {} 中的值是此对象中的属性。可以简化上述的开发。 欢迎页面 !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body a hrefthymeleaf/expression1标准变量表达式/a a hrefthymeleaf/expression2选择变量表达式/a /body /html controller存放数据 GetMapping(/expression2)public String expression2(Model model){model.addAttribute(student,new Student(Jack,18));return expression2;} expression2.html取出数据使用th:object *{key}简化上述的开发 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleexpression2/title /head body!--前缀--div th:object${student}!--属性--p th:text*{name}/pp th:text*{age}/p/div!--实际上使用*{}也可以完整的表示对象的属性值和${}效果一样--p th:text*{student.name}/p /body /html ③链接表达式URL表达式 语法{链接 url} 。 说明主要用于链接、地址的展示可用于 script src... , link href... a href.. ,form action... img src...等可以在 URL 路径中动态获取数据 。 欢迎页面index.html !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body a hrefthymeleaf/expression1标准变量表达式/a a hrefthymeleaf/expression2选择变量表达式/a a hrefthymeleaf/expression3链接表达式/a /body /html controller测试 package com.zl.controller;import com.zl.pojo.Student; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;Controller RequestMapping(/thymeleaf) public class ThymeleafExpressionController {GetMapping(/expression1)public String expression1(Model model){model.addAttribute(student,new Student(Jack,18));return expression1;}GetMapping(/expression2)public String expression2(Model model){model.addAttribute(student,new Student(Jack,18));return expression2;}// 链接表达式GetMapping(/expression3)public String expression3(Model model){model.addAttribute(userId,1001);model.addAttribute(userName,Jack);return expression3;}// 测试连接表达式GetMapping(/query1)ResponseBodypublic String query1(){ // 无参return id;}GetMapping(/query2)ResponseBodypublic String query2(Integer id){ // 一个参数return idid;}GetMapping(/query3)ResponseBodypublic String query3(Integer id,String name){return idid,namename;} }expression3.html !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleexpression3/title /head body!--使用绝对路径--a th:href{http://www.baidu.com}链接到百度/a!--使用相对路径--a th:href{/thymeleaf/query1}测试无参链接表达式/a!--使用字符串拼接的方式--a th:href{/thymeleaf/query2?id${userId}}测试一个参数的链接表达式/a!--常用的传参方式--a th:href{/thymeleaf/query2(id${userId})}常用的传参方式/aa th:href{/thymeleaf/query3(id${userId},name${userName})}测试两个参数的链接表达式/a /body /html 3. Thymeleaf的属性 大部分属性和 html 的一样只不过前面加了一个 th 前缀。 加了 th 前缀的属性是经过模版引擎处理的。 在属性上也可以使用变量表达式 ①th:action 定义后台控制器的路径类似标签的 action 属性主要结合 URL 表达式,获取动态变量 form idlogin th:action{/login} th:methodpost....../form ②th:method 设置请求方法 form idlogin th:action{/login} th:method${methodAttr}/form ③th:href 定义超链接主要结合 URL 表达式,获取动态变量 a th:href{/query/student}相对地址没有传参数/a ④th:src 用于外部资源引入比如script标签的 src 属性img标签的 src 属性常与{}表达式 结合使用在 SpringBoot 项目的静态资源都放到 resources 的 static 目录下放到 static 路径 下的内容写路径时不需要写上 static script typetext/javascript th:src{/js/jquery-3.4.1.js}/script ⑤th:text 用于文本的显示该属性显示的文本在标签体中如果是文本框数据会在文本框外显示 要想显示在文本框内使用 th:value input typetext idrealName namereaName th:text${realName} ⑥th:style 设置样式 a th:onclickfun1(${user.id}) th:stylecolor:red点击我/a 例1 第一步欢迎页面 a hrefthymeleaf/property模板的属性/a 第二步controller准备数据 package com.zl.controller;import com.zl.pojo.Student; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;Controller RequestMapping(/thymeleaf) public class ThymeleafExpressionController {GetMapping(/property)public String useProperty(Model model){model.addAttribute(methodAttr,post);model.addAttribute(id,123);model.addAttribute(userName,Jack);model.addAttribute(userValue,lisi);return html-property;} }第三步html-property.html获取数据 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title模板的属性/title /head bodyform th:action{/loginServet} th:method${methodAttr}input th:typetext th:name${userName} th:value${userValue}!--绑定按钮事件--input th:typebutton idbtn th:onclickbtnOnclick() value按钮/formscript typetext/javascriptfunction btnOnclick() {alert(按钮单击了);}/script/body /html F12查看 ⑦th:each 重点 这个属性非常常用比如从后台传来一个对象集合那么就可以使用此属性遍历输出它与 JSTL 中的c:forEach类似此属性既可以循环遍历集合也可以循环遍历数组及 Map 例2循环list集合或数组 第一步欢迎页面 a hrefthymeleaf/eachList循环遍历List/a 第二步controller准备数据 package com.zl.controller;import com.zl.pojo.Student; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;import java.util.ArrayList; Controller RequestMapping(/thymeleaf) public class ThymeleafExpressionController {GetMapping(/eachList)public String eachList(Model model){// 准备数据ArrayListStudent studentList new ArrayList();Student s1 new Student(zhangsan, 18);Student s2 new Student(lisi, 20);Student s3 new Student(wangwu, 22);studentList.add(s1);studentList.add(s2);studentList.add(s3);// 放入域当中model.addAttribute(students,studentList);return student-list;}}第三步student-list.html获取数据 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleeachList/title /head bodytable border1px th:aligncenter width50%trth姓名/thth年龄/th/trtr th:eachstu:${students}td th:text${stu.name}/tdtd th:text${stu.age}/td/tr /table /body /html 补充实际上完整的遍历格式如下 div th:each集合循环成员,循环的状态变量:${key}p th:text${集合循环成员} /p /div循环的状态变量可以定义也可以不定义通过该变量可以获取如下信息 ①index: 当前迭代对象的 index从 0 开始计算 ②count: 当前迭代对象的个数从 1 开始计算这两个用的较多 ③size: 被迭代对象的大小 ④current: 当前迭代变量stuState.current就相当于循环变量stu ⑤even/odd: 布尔值当前循环是否是偶数/奇数从 0 开始计算 ⑥first: 布尔值当前循环是否是第一个 ⑦last: 布尔值当前循环是否是最后一个 例如获取当前迭代对象的个数 注意循环体信息 userStat 也可以不定义则默认采用迭代变量加上 Stat 后缀即 userStat。 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleeachList/title /head bodytable border1px th:aligncenter width50%trth序号/thth姓名/thth年龄/th/tr!--添加状态变量stuState--tr th:eachstu,stuState:${students}td th:text${stuState.count}/tdtd th:text${stu.name}/tdtd th:text${stu.age}/td/tr /table /body /html 执行结果 例3循环map集合 以key和value的方式存放数据 GetMapping(/eachMap)public String eacMap(Model model){// 准备数据HashMapString, Student studentHashMap new HashMap();Student s1 new Student(zhangsan, 18);Student s2 new Student(lisi, 20);Student s3 new Student(wangwu, 22);studentHashMap.put(s1,s1);studentHashMap.put(s2,s2);studentHashMap.put(s3,s3);// 放入域当中model.addAttribute(studentHashMap,studentHashMap);return student-map;} 取出数据 ①调用循环变量的key属性拿到Map集合的key ②调用循环变量的value属性拿到Map集合的value此时拿到的value是Java对象可以继续点下去取里面的成员变量属性 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleeachList/title /head body div stylemargin-left: 400pxdiv th:eachstuMap:${studentHashMap}p th:text${stuMap.key}/pp th:text${stuMap.value}/pp th:text${stuMap.value.name}/pp th:text${stuMap.value.age}/phr th:colorred/div /div/body /html 执行结果 例4ListMap复杂的List和Map集合的嵌套 存入两个map集合的数据到list集合 GetMapping(/eachListMap)public String eachListMap(Model model){// 准备一个listmapListMapString,Student listmap new ArrayList();// 第一个map1数据HashMapString, Student map1 new HashMap();Student s1 new Student(zhangsan, 18);Student s2 new Student(lisi, 20);map1.put(s1,s1);map1.put(s2,s2);// 第二个map2数据HashMapString, Student map2 new HashMap();Student s3 new Student(Jack, 22);Student s4 new Student(Rose, 22);map2.put(s3,s3);map2.put(s4,s4);// 把map集合放入list集合当中listmap.add(map1);listmap.add(map2);// 放入域当中model.addAttribute(listmap,listmap);return student-listmap;}两层each循环取出数据 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleeachList/title /head body div stylemargin-left: 400pxdiv th:eachstuListMap:${listmap}!--得到每个map--!--再循环一层得到每个map的key和value--div th:eachmap:${stuListMap}p th:text${map.key}/pp th:text${map.value}/p/divhr th:colorred/div /div/body /html 执行结果 ⑧条件判断 if-unless th:if : 判断语句当条件为true显示html标签体内反之不显示 没有else语句。  语法th:if”boolean 条件” 条件为 true 显示体内容 th:unless 是 th:if 的一个相反操作条件为 false 显示体内容 第一步index.html a hrefthymeleaf/ifunless判断语句if-unless/abr 第二步controller发出请求 GetMapping(/ifunless)public String ifUnless(Model model){// 有正常数据model.addAttribute(sex,m);// 数据为空字符串model.addAttribute(name,);// 数据为nullmodel.addAttribute(isOld,null);return if-unless;}第三步前端进行判断 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title条件判断if-unless/title /head body div stylemargin-left: 400pxp th:if${sex m}我是男孩子/p!--空字符串是true--p th:if${name}name是/p!--null是false--p th:if${isOld}isOld是null/p!--unless条件为false显示内容--p th:unless${isOld}isOld是null------/p /div/body /html 执行结果 ①if是条件为true显示结果unless是条件为假显示结果 ②空字符串“”会被当做true来处理 ③nulll会被当做fale处理 ⑨switch-case 判断语句 语法类似 java 中的 switchcase最多只能有一个case匹配成功。 div th:switch要比对的值p th:case值1结果1/pp th:case值2结果2/pp th:case*默认结果/p以上的case只有一个语句执行/div controller存储数据 GetMapping(/switchcase)public String switchCase(Model model){model.addAttribute(a,m);model.addAttribute(b,f);model.addAttribute(c,mf);return swicth-case;} html取出数据并判断 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleswicth-case条件判断/title /head body div stylemargin-left: 400pxdiv th:switch${a}p th:casem男/pp th:casef女/pp th:case*未知/p/divhr th:colorreddiv th:switch${b}p th:casem男/pp th:casef女/pp th:case*未知/p/divhr th:colorreddiv th:switch${c}p th:casem男/pp th:casef女/pp th:case*未知/p/div /div /body /html 执行结果 总结一旦某个 case 判断值为 true剩余的 case 则都当做 false“*”表示默认的case前面的case 都不匹配时候执行默认的 case。 ⑩th:inline内联 th:inline 有三个取值类型 (text, javascript 和 none) none就表示无的意思。 内联 text 可以让 Thymeleaf 表达式不依赖于 html 标签直接使用内敛表达式[[表达式]]即可获取动 态数据要求在父级标签上加 th:inline “text”属性。  controller存储数据 package com.zl.controller;import com.zl.pojo.Student; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;import java.security.PublicKey; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;Controller RequestMapping(/thymeleaf) public class ThymeleafExpressionController {GetMapping(/inline/text)public String inlineText(Model model){model.addAttribute(name,Jack);model.addAttribute(age,22);return inline-text;} }使用内联text取出数据 第一步父级标签上加 th:inline “text”实际上这部分可以省略。 第二步使用[[${变量的方式}]]。 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleinline-text/title /head body div stylemargin-left: 400px th:inlinetext!--使用html标签--p th:text${name}/pbr!--内联text--[[${age}]] /div/body /html 成功取出数据 内联javascript 就是在 js 中获取模版中的数据  使用内联javascript取出上述存取的数据 第一步引入script标签在标签中引入th:inline “javascript” 第二步在js中取出数据取出方式和内联text相同 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleinline-text/title /head body !--按钮绑定点击事件-- button onclickbtnOnclick()按钮/button script typetext/javascript th:inlinejavascript/*使用js代码获取数据*/var name [[${name}]];var age [[${age}]];!--直接输出打印--alert(用户名name,年龄age);!--绑定事件使用回调函数--function btnOnclick(){alert(用户名name,年龄age);} /script /body /html 执行结果 4. 字面量 ①文本字面量单引号...包围的字符串为文本字面量 ②数字字面量 ③boolean字面量 ④null字面量 第一步欢迎页面index.html a hrefthymeleaf/text字面量/a 第二步域中存数据 GetMapping(/text)public String text(Model model){model.addAttribute(sex,m);model.addAttribute(isLogin,true);model.addAttribute(age,10);model.addAttribute(name,null);model.addAttribute(city,北京);return text;}第三步取出数据 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title字面量/title /head body !--文本字面量单引号包裹的字符串-- p th:text城市是${city}/p !--文本字面量实际上使用内联也能完成-- div th:inlinetext我的城市是[[${city}]] /div!--数字字面量-- p th:if${age 8}age8/p !--boolean字面量-- p th:text${isLogin true}登陆了/p !--null字面量-- p th:if${name null}name是null/p /body /html 执行结果 5.字符串连接重要 第一种方式 使用 单引号括起来字符串 使用 连接其他的 字符串或者表达式 p th:text我是${name},我所在的城市${city}数据显示/p 第二种方式使用双竖线||例如|字符串内容| p th:text|我是${name},我所在城市${city|显示数据 /p controllelr存储数据 GetMapping(/stringbuf)public String stringBuf(Model model){model.addAttribute(name,Jack);model.addAttribute(age,45);model.addAttribute(student,new Student(张三,16));return stringbuf;} 进行字符串的拼接 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org body div stylemargin-left: 400px!--第一种方式--p th:text 我是${name},今年${age},岁带的学生信息是${student} /p\!--第二种方式--hr stylecolor: chocolatep th:text|我是${name},今年${age}岁,带的学生信息是${student}|/p /div /body headmeta charsetUTF-8title字符串的拼接/title /head /html 执行结果 6. 运算符 ①算术运 算 ,  - , * , / , % ②关系比较 : , , , ( gt , lt , ge , le ) ③相等判断 , ! ( eq , ne ) ④三元运算符表达式   true的结果 : false的结果 controller存储数据 GetMapping(/data)public String data(Model model){model.addAttribute(name1,null);model.addAttribute(name2,Jack);model.addAttribute(age,18);model.addAttribute(isLogin,true);return data;} 进行数据的运算符比较 注对于内层嵌套的三元运算符内层嵌套的不用${}。 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title运算符的比较/title /head body div stylemargin-left: 40px!--算术运算符--p th:text${age20}/pp th:text${10 % 3}/p!--关系运算符--p th:if${age 10}年龄大于10/pp th:if${age gt 10}年龄大于10/p!--相等判断--p th:if${name1 null}name1是null/pp th:if${name2 ne null}name2不是null/p!--三步运算符--p th:text${isLogin true ? 用户已登录 : 用户未登录}/p!--三元运算符的嵌套--p th:text${isLogin true ? (age gt 10 ? 用户已成年 : 用户未成年) : 用户未登录}/p /div /body /html 执行结果 7. Thymeleaf内置对象 模板引擎提供了一组内置的对象这些内置的对象可以直接在模板中使用这些对象由# 号开始引用我们比较常用的内置对象 ①#request 表示 HttpServletRequest ②#session 表示 HttpSession 对象  ③session  本质上是一个Map集合是#session的简单表示方式用来获取session中指定的key的值 #session.getAttribute(loginname) session.loginname controller存数据 GetMapping(/baseObject)public String baseObject(Model model, HttpServletRequest request,HttpSession session){model.addAttribute(name,Jack);request.setAttribute(requestData,request作用域中的对象);session.setAttribute(sessionData,session作用域中的对象);return baseObject;} 一获取作用域中的数据 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置对象/title /head bodydiv stylemargin-left: 400pxp th:text${name}/pp th:text${#request.getAttribute(name)}/p!--#request本质是一个HttpServletRequest--p th:text${#request.getAttribute(requestData)}/p!--#sessiont本质是一个HttpSession--p th:text${#session.getAttribute(sessionData)}/p!--session本质是一个Map--p th:text${session.sessionData}/p/div /body /html 执行结果 思考剖析session对象实际上session对象本质上是一个Map存入的数据以key和value的形式存储所以session.key的方式底层实际上就是调用map.get(key)的方式取出value数据 二使用内置对象的方法 ①getRequestURL()获取完整的地址信息不包含参数 ②getRequestURI()获取地址信息不包含IP地址、端口号、参数 ③getQueryString()获取参数信息 ④getContextPath()获取根路径 ⑤getServerName()获取IP地址 ⑥getServerPort()获取端口号 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置对象/title /head bodydiv stylemargin-left: 400px!--完整地址--p th:text${#request.getRequestURL()}/p!--相对的地址--p th:text${#request.getRequestURI()}/p!--参数--p th:text${#request.getQueryString()}/p!--根路径--p th:text${#request.getContextPath()}/p!--IP地址--p th:text${#request.getServerName()}/p!--端口号--p th:text${#request.getServerPort()}/p/div /body /html 执行结果 8. Thymeleaf内置工具类对象 ①模板引擎提供的一组功能性内置对象可以在模板中直接使用这些对象提供的功能方法 ②工作中常使用的数据类型如集合时间数值可以使用 Thymeleaf 的提供的功能性对 象来处理它们; ③内置功能对象前都需要加#号内置工具类对象一般都以 s 结尾 官方手册Tutorial: Using Thymeleaf Cat类 package com.zl.vo;public class Cat {private String name;public Cat() {}public Cat(String name) {this.name name;}Overridepublic String toString() {return Cat{ name name \ };}public String getName() {return name;}public void setName(String name) {this.name name;} }Dog类 package com.zl.vo;public class Dog {private String name;public Dog() {}public Dog(String name) {this.name name;}Overridepublic String toString() {return Dog{ name name \ };}public String getName() {return name;}public void setName(String name) {this.name name;} }Zoo类 package com.zl.vo;public class Zoo {private Cat cat;private Dog dog;public Zoo() {}public Zoo(Cat cat, Dog dog) {this.cat cat;this.dog dog;}Overridepublic String toString() {return Zoo{ cat cat , dog dog };}public Cat getCat() {return cat;}public void setCat(Cat cat) {this.cat cat;}public Dog getDog() {return dog;}public void setDog(Dog dog) {this.dog dog;} }controller存数据 package com.zl.controller;import com.zl.pojo.Student; import com.zl.vo.Cat; import com.zl.vo.Dog; import com.zl.vo.Zoo; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.security.PublicKey; import java.util.*;Controller RequestMapping(/thymeleaf) public class ThymeleafExpressionController {GetMapping(/utilObject)public String utilObject(Model model){model.addAttribute(mydate,new Date());model.addAttribute(number,32.636);model.addAttribute(str,hello);ListString list Arrays.asList(Jack,Rose,King);model.addAttribute(list,list);Cat cat new Cat(小猫);Dog dog new Dog(二哈);zoo.setCat(cat);// zoo.setDog(dog);model.addAttribute(zoo,zoo);return utilObject;} } 一#dates---处理日期的 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置工具类对象/title /head body div stylemargin-left: 400pxp日期工具类对象#dates/p!--默认的格式化方式--p th:text${#dates.format(mydate)}/p!--自定义格式化方式--p th:text${#dates.format(mydate,yyyy-MM-dd)}/pp th:text${#dates.format(mydate,yyyy-MM-dd HH:mm:sss)}/p!--只获取对应的年月日--p th:text${#dates.year(mydate)}/pp th:text${#dates.month(mydate)}/p !--数字--p th:text${#dates.monthName(mydate)}/p!--字符串--p th:text${#dates.day(mydate)}/p!--获取当前的时间--p th:text${#dates.createNow()}/p /div /body /html 执行结果 二#numbers---处理数字的 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置工具类对象/title /head body div stylemargin-left: 400pxp数字工具类对象#dates/p!--格式化带有货币符号还会四舍五入--p th:text${#numbers.formatCurrency(number)}/p!--保留整数多少位保留小数多少位--p th:text${#numbers.formatDecimal(number,5,2)}/p /div /body /html 执行结果 三#strings---处理字符串的 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置工具类对象/title /head body div stylemargin-left: 400pxp字符串工具类对象#strings/p!--转大写--p th:text${#strings.toUpperCase(str)}/p!--某个字符串在当前字符串存在的下标--p th:text${#strings.indexOf(str,ll)}/p!--截取串--p th:text${#strings.substring(str,1,3)}/p!--字符串的拼接--p th:text${#strings.concat(str,world)}/p!--字符串的长度--p th:text${#strings.length(str)}/p /div /body /html 执行结果 四#lists---处理集合的 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置工具类对象/title /head body div stylemargin-left: 400pxp集合工具类对象#lists/p!--集合中含有几个数据--p th:text${#lists.size(list)}/p!--是否包含Rose字符串--p th:if${#lists.contains(list,Rose)}list集合包含Rose/p!--集合是否为空--p th:text${#lists.isEmpty(list)}/p /div /body /html 执行结果 五null处理 正常取出数据 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8title内置工具类对象/title /head body div stylemargin-left: 400pxp处理null/p!--正常取出数据--p th:text${zoo.dog.name}/pp th:text${zoo.cat.name}/p /div /body /html 执行结果 思考如果此时对于cat没有赋上值 此时会出现500错误服务器内部错误 实际上是出现了空引用如何避免呢 在引用的后面使用问号如果引用存在就可以向下取属性如果当前引用为空直接不显示结果 p th:text${zoo?.cat?.name}/p 执行结果 9.自定义模板内容复用 自定义模板是复用的行为可以把一些内容多次重复使用 模板语法 对于一个自定义模板的使用主要包括两部分 定义模板 模板定义语法th:fragment模板自定义名称 div th:fragmentheadp大连/ppwww.dlu.com/p /div 使用模板 引用模板语法 ~{templatename :: selector} 或者 templatename :: selector ①其中templatename:  文件名称selector 自定义模板名称 ②对于使用模板有包含模板th:include 插入模板(th:insert) 插入模板和包含模板 注对于插入模板可以理解为整体的插入对于包含模板可以理解为整体的替换 第一步模板的定义 head.html !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head body div th:fragmenttoppwww.baidu.com/pp百度官网/p /div /body /html 第二步欢迎页面index.html a hrefthymeleaf/customtpl自定义模板/abr第三步controller跳转到customtpl页面 GetMapping(/customtpl)public String customtpl(){return customtpl;} 第四步customtpl页面使用插入模板和包含模板 ①插入模板 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head body div stylemargin-left: 400pxh1插入模板insert/h1!--第一种方式--div th:insert~{head :: top}/divhr!--第二种方式--div th:inserthead :: top/div /div /body /html 执行结果成功插入原来html页面的内容 F12打开前端代码分析嵌套进去 ②包含模板 h1包含模板include/h1 !--第一种方式-- div th:include~{head :: top}/div hr stylecolor: red !--第二种方式-- div th:includehead :: top/div F12打开前端代码分析完全替换 整个html页面作为模板插入  footer.html !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head body divfooter.htmlwww.baidu.com /div/body /html 此时把整个footer.html页面插入到 customtpl页面 注前面主要是将某一个代码片段引入到其它页面这里讲解的是将整个html页面引入到其它页面。 语法格式 ①th:include/insert文件名 :: 文件格式后缀名 ②th:include/insert文件名省略后缀名 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head body div stylemargin-left: 400pxh1引入整个footer.html到此页面/h1!--第一种方式--p th:insertfooter :: html/p!--第二种方式--p th:insertfooter/p /div /body /html 成功引入 思考以上是同级目录下的整个html页面的引入如果是其它目录呢  在templates目录下有一个common目录common目录下有一个left.html left.html  !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head bodyh1我是一个标签/h1 /body /html 引入其它目录下的页面到此页面 !DOCTYPE html html langen xmlns:thhttp://www.thymeleaf.org headmeta charsetUTF-8titleTitle/title /head body div stylemargin-left: 400pxh1引入其它目录下的页面到此页面/h1!--第一种方式--p th:insertcommon/left :: html/p!--第二种方式--p th:insertcommon/left/p /div /body /html 执行结果成功引入 图书推荐《巧用ChatGPT轻松玩转新媒体运营》 本次送书 2本  活动时间截止到 2023-10-12 00:00:00。 抽奖方式利用程序进行抽奖。 参与方式关注博主只限粉丝福利哦、点赞、收藏评论区随机抽取最多三条评论 关键点 ★超实用 通过80多个实战案例和操作技巧使读者能够快速上手并灵活运用ChatGPT技术及提高运营能力。 ★巨全面 涵盖10多个新媒体领域文案写作图片制作社交媒体运营爆款视频文案私域推广广告策划电商平台高效运营等。 ★真好懂 以通俗易懂的语言解释ChatGPT的原理及应用轻松提高新媒体运营能力。 ★高回报 学习本书全面提升运营能力大大提高工作效率促进职业发展实现自我价值。 内容简介 本书从ChatGPT的基础知识讲起针对运营工作中的各种痛点结合实战案例如文案写作、图片制作、社交媒体运营、爆款视频文案、私域推广、广告策划、电商平台高效运营等手把手教你使用ChatGPT进行智能化工作。此外还介绍了通过ChatGPT配合Midjourney、D-ID等AI软件的使用进一步帮助提高运营工作的效率。 本书内容通俗易懂案例丰富实用性较强特别适合想要掌握ChatGPT对话能力的读者和各行各业的运营人员如互联网运营人员、自媒体运营人员、广告营销人员、电商运营人员等。 另外本书也适合作为相关培训机构的教材使用。 当当网链接当当图书 京东的链接京东安全
http://wiki.neutronadmin.com/news/351570/

相关文章:

  • 没备案的网站可以做淘客html5 手机 网站
  • 国外虚拟主机 两个网站绿色大气网站模板
  • c asp做网站动画设计公司
  • 免费成品网站模板滁州网站建设设计
  • 贵州省文化旅游网站建设的必要性网站开发流程及进度安排
  • php怎么做直播网站吗乐器产品主要在什么网站做推广
  • 北京专业网站制作服务做网站 视频
  • 湛江专业建站wordpress文章展示
  • 兖州城乡建设局网站免费微信营销系统
  • 网站建设项目报告总结单屏网站设计
  • 给个网站免费的做网站订阅号
  • 文化传媒公司网站模板海淀网站建设联系方式
  • 怎么介绍做网站技术深圳华强北手机城
  • 挂机宝可以做网站吗源代码管理网站
  • 江苏城乡建设教育网站正常做一个网站多少钱
  • wordpress源码网站主题模板在线设计制作
  • 帮人做ppt的网站wordpress数据库设置
  • 个人网站开发多少钱门户网站管理系统
  • 当今做哪个网站能致富小红书推广文案
  • 商城网站 报价 方案湖南微网站开发
  • 石家庄做网站公司汉狮价格房产信息查询
  • 重庆企业网站备案要多久时间北京的公司有哪些
  • 做网站建设找哪家好网站策划论坛
  • aje网站润色织梦 手机网站
  • 免费的公众号排版工具如何做网络推广优化
  • 宁波高新区建设局网站wordpress登录可见代码
  • 房屋建筑设计网站网站通栏是什么
  • 静态网站开发基础宠物用品技术支持 东莞网站建设
  • 众筹平台网站建设wordpress右侧空白
  • 北京网站优化哪家公司好安徽安庆