看一下代碼:html
@Controller public class HelloController { //讀取枚舉值 @Value("#{T(com.example.demo.model.EnumList.EnumList.TrackTraceState).Booking.getEnumItem().getItemCN()}") private String pwd; //讀取方法 @Value("#{T(com.example.demo.controller.HelloController).GetName()}") private String name; public static String GetName() { return "hello"; } //讀取配置文件 @Value("${girl.age}") private Integer age; @RequestMapping("/index.do") public String say(ModelMap mode) { User u=new User(); u.setUserName(name); u.setAge(age); u.setPassword(pwd); mode.addAttribute("user", u); return "say"; } }
application.yml:app
girl:
name: uiw
age: 33
html:ui
<div th:text="${user.userName}"></div> <div th:text="${user.password}"></div> <div th:text="${user.age}"></div> <div th:text="${T(com.example.demo.model.EnumList.EnumList.IsApprovalEnum).Approved.getEnumItem().getItemCN()}" />
pwd: 調用的枚舉值,以及方法返回枚舉值的中文名spa
name:調用的靜態方法GetNamecode
age:讀取配置文件htm
最後一個:是thymeleaf 調用後臺枚舉值的方法。blog
呈現:get
PS:io
${} 讀取上下文的屬性值class
#{} 啓用Spring表達式,具備運算能力