springboot EL @Value
一,springboot中
看一下代码:
@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表达式,具有运算能力
二,SpringMvc / Module模块引用(例子是SqlHelper)
首先springmvc-servlet.xml中 引入属性文件
<!-- 引入属性文件 -->
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/env.properties</value>
<value>classpath:properties/jdbc.properties</value>
</list>
</property>
</bean>
继续添加模块的bean
<bean id="sqlHelper" class="com.kintech.SQLServer.SqlHelper" />
调用时使用 @Autowired
@Autowired
SqlHelper sh; @RequestMapping(value = "test01.do")
public String test01(ModelMap mode) {
sh.getConn();
return "test/test01";
}
看一下SqlHelper

springboot EL @Value的更多相关文章
- springboot启动tomcat报错java.lang.NoClassDefFoundError: javax/el/ELManager仅记录
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'o ...
- 外部tomcat发布springboot项目步骤和异常处理:java.lang.NoClassDefFoundError: javax/el/ELManager
- Thymeleaf模板引擎与springboot关联后,在html中无法使用el表达式获取model存的值
头部引入了thymeleaf <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thy ...
- Springboot基础篇
Springboot可以说是当前最火的java框架了,非常适合于"微服务"思路的开发,大幅缩短软件开发周期. 概念 过去Spring充满了配置bean的xml文件,随着spring ...
- springboot(四):thymeleaf使用详解
在上篇文章springboot(二):web综合开发中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thymeleaf的使用.thymeleaf 是新一代的模板引擎,在spring4. ...
- (二)springboot整合thymeleaf模板
在我们平时的开发中,用了很久的jsp作view显示层,但是标签库和JSP缺乏良好格式的一个副作用就是它很少能够与其产生的HTML类似.所以,在Web浏览器或HTML编辑器中查看未经渲染的JSP模板是非 ...
- 整合springboot(app后台框架搭建四)
springboot可以说是为了适用SOA服务出现,一方面,极大的简便了配置,加速了开发速度:第二方面,也是一个嵌入式的web服务,通过jar包运行就是一个web服务: 还有提供了很多metric,i ...
- SPRINGBOOT 读书笔记
Spring基础 Spring的发展 xml配置 注解配置 Java配置 Spring模块:核心容器 AOP 消息 web 数据访问集成 常用的:@Component @Service @Reposi ...
- 解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE
问题 如下: 2017-07-16 08:50:57.436 INFO 13524 --- [ main] c.p.p.web.PointshopWebApplication ...
随机推荐
- js浮点数的计算总结
在js浮点值的计算中,很多时候会出现不准确的情况,如下面的情况 console.log(2.2 + 2.1) // 4.300000000000001 console.log(2.2 - 1.9) / ...
- pytest-文件名类名方法名执行部分用例
pytest test_class_01.py 执行文件名 pytest -v -s test_class_01.py 执行文件名 pytest -v test_class_01.py::TestCl ...
- 结对编程项目报告--四则运算CORE
<!doctype html> sw_lab2.mdhtml {overflow-x: initial !important;}#write, body { height: auto; } ...
- centos7 安装KDE
下载安装了centos7 64位系统之后.初始化安装的是GNOME桌面系统.因为是按照鸟哥的Linux在学习,所以需要安装kde. 首先需要root权限. 打开终端. 输入su root密码.进入ro ...
- Codeforces 1140E DP
题意:给你一个数组,如果数组中的某个位置是-1那就可以填1到m的数字中的一个,但是要遵守一个规则:不能出现长度为奇数回文的子串,问合法的填法有多少种? 思路:不出现长度为奇数的回文子串,只需不出现长度 ...
- js字符与ASCII码互转的方法
大写字母A-Z对应的ASCII码值是65-90 小写字母a-z对应的ASCII码值是97-122 将字母转为ascii码的方法: 将ascii码转为对应字母的方法:
- 明年将制定个人信息保护法 网站部署https迫在眉睫
12月20日,全国人大常委会法工委举行第三次记者会.全国人大常委会法工委发言人岳仲明表示,中国明年将制定个人信息保护法.数据安全法等. 数据泄露为何频频出现 你是否经常接到骚扰电话?推销.诈骗等等均有 ...
- (补充)9.Struts2中的OGNL表达式
OGNL表达式概述 1. OGNL是Object Graphic Navigation Language(对象图导航语言)的缩写 * 所谓对象图,即以任意一个对象为根,通过OGNL可以访问与这个对象关 ...
- CSIC_716_20191129【 单例模式 的五种实现方式】
单例模式 单例模式:在确定类中的属性和方法不变时,需要反复调用该类的情况. 让所有通过该类实例化出的对象,都指向同一个内存地址. 优点:节省内存空间. 单例模式有五种表现形式: 1.通过class ...
- windows下安装jenkins初级(1)
这里是基于Windows系统下安装Jenkins 首先下载jenkins 下载地址:https://jenkins.io/download/ 选择所需要的系统 我这里选择Windows 开始安装 一直 ...