看一下代码:
@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:
girl:
name: uiw
age: 33
html:
<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: 调用的枚举值,以及方法返回枚举值的中文名
name:调用的静态方法GetName
age:读取配置文件
最后一个:是thymeleaf 调用后台枚举值的方法。
呈现:
PS:
${} 读取上下文的属性值
#{} 启用Spring表达式,具有运算能力