首页 > 其他分享 >thymeleaf获取作用域的值

thymeleaf获取作用域的值

时间:2023-09-13 09:45:32浏览次数:44  
标签:map 作用域 代码 setAttribute 获取 thymeleaf put 取值 前端

参考:https://blog.csdn.net/qq_43634655/article/details/126424130

从session取值

  1. 后端代码
	Map<String,Object> map = new HashMap<>();
	map.put("id","1001");
	map.put("name","小虎");
	map.put("age","18");
	map.put("message","完美世界");
	map.put("code","200");
	session.setAttribute("map",map);

  1. 前端代码
<!--前面要加session-->
<h2 th:text="${session.map.name}"></h2>

从model取值

  1. 后端代码
	List<User> allUser = userMapper.findAllUser();
    	model.addAttribute("userList",allUser);

  1. 前端代码
 <tbody th:each="user:${userList}">
       <tr>
             <td th:text="${user.id}"></td>
             <td th:text="${user.name}"></td>
             <td th:text="${user.password}"></td>
             <td th:text="${user.sex == 1 ? '男':'女' }"></td>
             <td th:text="${user.sex}"></td>
             <td th:text="${#dates.format(user.birthday,'yyyy-MM-dd')}"></td>
             <td th:text="${#dates.format(user.createTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
             <td th:text="${#dates.format(user.updateTime, 'yyyy-MM-dd HH:mm:ss')}"></td>
             <td>
                 <a class="btn btn-sm btn-primary">更新</a>
                 <a class="btn btn-sm btn-warning">删除</a>
             </td>
     	</tr>
 </tbody>

从request取值

  1. 后端代码
 request.setAttribute("requestAge", 100);
  1. 前端代码
 <span style="color: red;" th:text="${requestAge}"></span><br />

从servletContext取值

  1. 后端代码
servletContext.setAttribute("applicationNum", 1);
  1. 前端代码
<span style="color: red;" th:text="${application.applicationNum}"></span><br /> 

标签:map,作用域,代码,setAttribute,获取,thymeleaf,put,取值,前端
From: https://www.cnblogs.com/hasome/p/17698666.html

相关文章

  • 【Spring Boot】Thymeleaf 模板引擎
     Thymeleaf组成:标签+表达式,标签是Thymeleaf的语法结构,而表达式就是语法里的内容实现  pom.xml添加依赖包<!--模板引擎Thymeleaf依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-b......
  • app备案公钥指纹包名获取
    APP备案是什么?听起来好像是个新词,其实跟网站域名备案差不多,目的为了限制一些非法套壳的APP,有了备案号就可以第一时间查到当前APP的开发者是谁。中国工信部于2023年8月份出台了新规定,要求移动应用制造商在通过应用市场销售前需向政府备案,8月底已经开始实行所有在国内运营的......
  • 简简单单教你如何用C语言实现获取当前所有可用网口!
    一、获取本机所有可用网卡名原理:在Linux系统中,/proc目录是一个位于内存中的伪文件系统。/proc目录是内核提供给我们的查询中心,通过查询该目录下的文件内容,可以获取到有关系统硬件及当前运行进程的信息,如CPU信息、负载信息、系统内存信息、磁盘IO信息等。其中文件:/proc......
  • 视频监控/安防监控/AI视频分析/边缘计算EasyCVR如何调取登录接口获取token?
    安防视频监控管理平台/视频汇聚/视频云存储平台EasyCVR能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、集中管理,实现视频资源的鉴权管理、按需调阅、全网分发、云存储、AI智能分析等,视频监控智能分析平台EasyCVR融合性强、开放度高、部署轻快,在智慧工地、智慧园区、......
  • js&jquery(写法对比):get input value(获取input值)
    1.JS写法 2.jquery写法 ......
  • 淘宝api:本地图片上传至淘宝 获取url(联合拍立淘接口)
    upload_img-上传图片到淘宝请求参数请求参数:imgcode=https://img14.360buyimg.com/n0/jfs/t1/52280/38/7464/140698/5d511f6bE08290bd7/f0bb32ddb47451e8.jpg参数说明:imgcode:base64加密后的图片内容(post方式),或者是直接上传(file方式)响应参数名称类型必须示例值描述......
  • WPF C# 使用扫描枪获取扫描数据
    通用扫码帮助类CommonScanCodeHelperusingSystem;usingSystem.Collections.Generic;usingSystem.Diagnostics;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Input;usingSystem.Windows.Threading;namespaceTools{///<summary>///通用扫......
  • C# Word VBA 获取所有CommandBarID
    foreach(Office.CommandBarControlcin.CommandBars.Controls){if(c.Id==){}}SubSample()Application.CommandBars.FindControl(ID:=927).ExecuteEndSubSub插入按钮名称和ID()DimwdAppAsObject'Word.ApplicationDimcbAsObject......
  • VBA 获取Word 所有CommandBar ID命令按钮
    Sub获取所有CommandBarID()DimwdAppAsObject'Word.ApplicationDimcbAsObject'CommandBarDimsAsString,idAsStringSetwdApp=CreateObject("Word.Application")WithwdApp......
  • springBoot spring6 无法加载 thymeleaf的,在html页面中无法智能感知 th:这些
    网上所有的坑我都试过了,还是无法解决问题,@ControllerpublicclassSellController{@RequestMapping("/test01")/*@ResponseBody*/publicStringindex(){return"test01";}}”test01“下面永远是波浪线,无论把网上查出来的解决问题的方案我......