日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

【SpringBoot】【Thyemeleaf 】【Spring EL表达式】 SPEL调用静态类、静态方法

發布時間:2024/9/19 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【SpringBoot】【Thyemeleaf 】【Spring EL表达式】 SPEL调用静态类、静态方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

  • spring 5.0.6.RELEASE
  • Thyemeleaf 3.0
  • SpringBoot 2.3.4.RELEASE

Spring EL表達式 調用靜態類、靜態方法

參考這里:https://docs.spring.io/spring-framework/docs/5.0.6.RELEASE/spring-framework-reference/core.html#expressions-types

The special T operator can be used to specify an instance of java.lang.Class (the type). Static methods are invoked using this operator as well. The StandardEvaluationContext uses a TypeLocator to find types and the StandardTypeLocator (which can be replaced) is built with an understanding of the java.lang package. This means T() references to types within java.lang do not need to be fully qualified, but all other type references must be.

Class dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class);Class stringClass = parser.parseExpression("T(String)").getValue(Class.class);boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class);

Thyemeleaf 調用靜態類、靜態方法

官方給的說明:https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#variables

We already mentioned that ${…} expressions are in fact OGNL (Object-Graph Navigation Language) expressions executed on the map of variables contained in the context.
For detailed info about OGNL syntax and features, you should read the OGNL Language Guide
In Spring MVC-enabled applications OGNL will be replaced with SpringEL, but its syntax is very similar to that of OGNL (actually, exactly the same for most common cases).

根據官方說明,Thyemeleaf 表達式為OGNL,調用靜態類、靜態方法的辦法按照OGNL的辦法做即可。
在Spring MVC下,SpringEL 替換了 OGNL。那么,在Spring MVC下,調用靜態類、靜態方法的辦法按照SpringEL的辦法做即可。

Spring MVC/SpringBoot示例:

比如,shiro的用戶頭像這么輸出:

<img th:with="avatar=${T(org.apache.shiro.SecurityUtils).getSubject().getPrincipal().avatar}" th:src="@{${#strings.defaultString(avatar,'/images/user-head.jpg')}}" class="user-info" />

參考

https://www.cnblogs.com/XingXiaoMeng/p/11409625.html

總結

以上是生活随笔為你收集整理的【SpringBoot】【Thyemeleaf 】【Spring EL表达式】 SPEL调用静态类、静态方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。