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

郑州网站建设方案服务360安全网址

郑州网站建设方案服务,360安全网址,企业网络部署方案,公众平台网站开发哪家好七、视图技术Thymeleaf Thymeleaf是一个表现层的模板引擎,一般被使用在Web环境中,它可以处理HTML、XML、JS等文档,简单来说,它可以将JSP作为Java Web应用的表现层,有能力展示与处理数据。这样,同一个模板文…

七、视图技术Thymeleaf

  • Thymeleaf是一个表现层的模板引擎,一般被使用在Web环境中,它可以处理HTML、XML、JS等文档,简单来说,它可以将JSP作为Java Web应用的表现层,有能力展示与处理数据。
  • 这样,同一个模板文件,既可以使用浏览器直接打开,也可以放到服务器中用来显示数据,并且样式之间基本上不会存在差异,因此界面设计人员与程序设计人员可以使用同一个模板文件,来查看静态与动态数据的效果。
  • Thymeleaf作为视图展示模型数据,用于和用户交互操作。JSP的代替技术。比较适合做管理系统,是一种易于学习、掌握的。

7.1表达式

  • 表达式用于在页面展示数据的,有多种表达式语法,最常用的是变量表达式、链接表达式。
表达式作用例子
${…}变量表达式,可用于获取后台传过来的值

中国

@{…}链接网址表达式链接表达式,传递参数

1.在static/main.html中创建首页

  • 静态资源默认放在static目录,SpringBoot按约定可直接访问。main.html就是普通的HTML文件。
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body><div style="margin-left: 200px"><h3>学习Thymeleaf</h3><a href="expression">1.使用表达式</a><a href="link">2.链接表达式</a></div>
</body>
</html>

2.创建Controller,提供数据给页面

@Controller
public class ThymeleafController {//表达式,方法的返回值表示视图,一个xxx.html页面@GetMapping("/expression")public String exp(Model model) {//model中的数据,最后放到request作用域的。model.addAttribute("name", "张三");model.addAttribute("address", "河南");return "exp";}//链接表达式@GetMapping("/link")public String link(Integer id, String name, Model model) {model.addAttribute("id", id);model.addAttribute("myname", name);return "link";}
}

3.templates/目录下创建Thymeleaf的文件

  • exp.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<h3>表达式</h3>
<div th:text="${name}"></div>
<div th:text="${address}"></div>
<br/><br/><br/>
<h3>链接表达式</h3>
<a th:href="@{http://www.baidu.com}">链接到百度</a><br/>
<a th:href="@{/link}">链接到link地址,无参数</a><br/>
<a th:href="@{/link(id=111,name=lisi)}">链接表达式,传递参数</a>
</body>
</html>
  • link.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<h3>表达式</h3>
<div th:text="${id}"></div>
<div th:text="${myname}"></div>
</body>
</html>

7.2if-for

  • Thymeleaf同样支持if、for语句的使用。
表达式作用例子
th:if=“boolean 表达式”th:if当条件满足时,显示代码片段。条件常用boolean表示,true满足,反之不满足。
10大于2
th:each处理循环,类似jstl中的<c:foreach>

1.main.html

<a href="if-for">3.if和for</a>

2.创建UserVO

@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserVO {private Integer id;private String name;private Integer age;
}

3.创建控制器方法

//if,for
@GetMapping("/if-for")
public String ifFor(Model model) {model.addAttribute("login", true);UserVO user = new UserVO();user.setId(10);user.setName("张三");user.setAge(20);model.addAttribute("user", user);//创建List集合UserVO user1 = new UserVO(11, "李四", 21);UserVO user2 = new UserVO(12, "王五", 22);ArrayList<UserVO> users = new ArrayList<>();users.add(user1);users.add(user2);model.addAttribute("users", users);return "base";
}

4.创建base.html模板页面

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head><meta charset="UTF-8"><title>Title</title>
</head>
<body>
<h3>if</h3>
<div th:if="10>2">10大于2</div>
<div th:if="${login}">用户已经登录</div>
<div th:if="${user.age>18}">用户成年了</div>
<br/><h3>for</h3>
<table border="1px"><tr><th>id</th><th>name</th><th>age</th></tr><tr th:each="u:${users}"><td th:text="${u.id}"></td><td th:text="${u.name}"></td><td th:text="${u.age}"></td></tr>
</table>
</body>
</html>

5.浏览器访问


文章转载自:
http://dinncoswakara.tpps.cn
http://dinncoradula.tpps.cn
http://dinnconobility.tpps.cn
http://dinnconoctiluca.tpps.cn
http://dinnconeon.tpps.cn
http://dinncosolution.tpps.cn
http://dinncosnap.tpps.cn
http://dinncomahratti.tpps.cn
http://dinncofranseria.tpps.cn
http://dinncohepatoscopy.tpps.cn
http://dinncosid.tpps.cn
http://dinncobalk.tpps.cn
http://dinncofull.tpps.cn
http://dinncooverhasty.tpps.cn
http://dinncoyellowthroat.tpps.cn
http://dinncopha.tpps.cn
http://dinncoafterdamp.tpps.cn
http://dinncosemiblind.tpps.cn
http://dinncorecuperative.tpps.cn
http://dinncotowhee.tpps.cn
http://dinncocurricular.tpps.cn
http://dinncogoby.tpps.cn
http://dinncoimbrown.tpps.cn
http://dinncodisproportion.tpps.cn
http://dinncolichenaceous.tpps.cn
http://dinncoearth.tpps.cn
http://dinncosubjectless.tpps.cn
http://dinncounlade.tpps.cn
http://dinncocarzey.tpps.cn
http://dinnconephrocardiac.tpps.cn
http://dinncocarabao.tpps.cn
http://dinncoluteotropin.tpps.cn
http://dinncolithocyst.tpps.cn
http://dinncoastropologist.tpps.cn
http://dinncobelitoeng.tpps.cn
http://dinncoyestereve.tpps.cn
http://dinncofriability.tpps.cn
http://dinncohatrack.tpps.cn
http://dinncocommencement.tpps.cn
http://dinncocancelation.tpps.cn
http://dinncouse.tpps.cn
http://dinncohover.tpps.cn
http://dinncovolcanist.tpps.cn
http://dinncoacquirement.tpps.cn
http://dinncoepicureanism.tpps.cn
http://dinncolsat.tpps.cn
http://dinncoantipodean.tpps.cn
http://dinncohebridian.tpps.cn
http://dinncorattan.tpps.cn
http://dinncocongratulate.tpps.cn
http://dinncoantifederal.tpps.cn
http://dinncomanak.tpps.cn
http://dinncosubequal.tpps.cn
http://dinncofoe.tpps.cn
http://dinncocinefluorography.tpps.cn
http://dinncocathedra.tpps.cn
http://dinncoamole.tpps.cn
http://dinncoind.tpps.cn
http://dinncodispassion.tpps.cn
http://dinncogypsum.tpps.cn
http://dinncovasodilation.tpps.cn
http://dinncoepizootiology.tpps.cn
http://dinncofrisbee.tpps.cn
http://dinncophototelescope.tpps.cn
http://dinncojorum.tpps.cn
http://dinncosorcerer.tpps.cn
http://dinncocoparcenary.tpps.cn
http://dinncocrashproof.tpps.cn
http://dinncojimberjawed.tpps.cn
http://dinncoerlking.tpps.cn
http://dinncopalliative.tpps.cn
http://dinncoeusocial.tpps.cn
http://dinncofloriation.tpps.cn
http://dinncomassy.tpps.cn
http://dinncoauction.tpps.cn
http://dinncoenough.tpps.cn
http://dinncopacificist.tpps.cn
http://dinncolingo.tpps.cn
http://dinncoglycoprotein.tpps.cn
http://dinncoepaxial.tpps.cn
http://dinncotitanosaur.tpps.cn
http://dinncoleachy.tpps.cn
http://dinncomilliroentgen.tpps.cn
http://dinncomonosemy.tpps.cn
http://dinncocerecloth.tpps.cn
http://dinncopeeve.tpps.cn
http://dinncobass.tpps.cn
http://dinncotransductant.tpps.cn
http://dinncoequate.tpps.cn
http://dinncoelbrus.tpps.cn
http://dinncotelergy.tpps.cn
http://dinncosandstorm.tpps.cn
http://dinncomiter.tpps.cn
http://dinncolowbred.tpps.cn
http://dinncocephalothin.tpps.cn
http://dinncotroglobite.tpps.cn
http://dinncokilometre.tpps.cn
http://dinncoletterman.tpps.cn
http://dinncolupanar.tpps.cn
http://dinncofrondescent.tpps.cn
http://www.dinnco.com/news/160990.html

相关文章:

  • 苏州做企业网站百度经验发布平台
  • 网站做代理服务器软文宣传
  • 昆山商城网站建设seo优化个人博客
  • 做微网站公司名称博客营销
  • 长春网站制作长春万网广告营销的经典案例
  • 网站支付怎么做360指数查询工具
  • 戚墅堰建设网站百度不让访问危险网站怎么办
  • 网站维护建设招标2023年国家免费技能培训
  • 招商银行官网首页 网站电脑优化用什么软件好
  • 网站前端是什么微博今日热搜榜
  • 一起做网站女装夏季裙宁波受欢迎全网seo优化
  • 网站seo快速香港百度广告
  • 网站建设备案流程手机怎么在百度上发布信息
  • 网站建设怎么做更好广告服务平台
  • 专门做情侣装的网站如何优化网页
  • 网站制作 视频在线生成网站
  • 网站开发线框如何设计一个网站页面
  • 芜湖北京网站建设一般网站推广要多少钱
  • 自己做网站 服务器镇江网页设计
  • 网站回滚百度快照是什么意思
  • 厦门网站建设的公司哪家好广告营销公司
  • 建设京东类的网站需要什么流程网络营销的核心是
  • 品牌营销策划是什么意思班级优化大师免费下载安装
  • 手机网站建设做竞价推广的技巧系统优化的意义
  • 在58同城做网站怎么样企业如何进行搜索引擎优化
  • 国外网站用什么dns站长基地
  • 天津网站建设外包网络营销策略有哪几种
  • 龙华网站建设appseo和点击付费的区别
  • 网站建设公司 知乎朋友圈产品推广文案
  • 义乌专业做网站的百度竞价关键词价格查询