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 ...
随机推荐
- window_mysql踩坑
https://blog.csdn.net/qq_37350706/article/details/81707862 先去官网下载点击的MySQL的下载 下载完成后解压 解压完是这个样子 配置系统环境 ...
- Netty 相关目录
Netty 相关目录 Netty 源码学习--客户端流程分析 Netty 源码学习--服务端流程分析 Netty 源码分析--ChannelPipeline Netty 源码学习--EventLoop ...
- js面向对象(一)---基本的概念、属性、方法
一.什么是面向对象编程 1.用对象的思想去写代码,就是面向对象编程 2.我们一直在使用对象,如数组Array 时间Date //我们把系统自带的对象,叫做系统对象 var arr = new A ...
- 怎样在Cocos2d-x中使用Lua脚本
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u013321328/article/details/25699545 笔者使用的是Cocos2d-x ...
- unix, PF_UNIX, AF_UNIX, PF_LOCAL, AF_LOCAL - 用于本地内部进程通讯的套接字。
SYNOPSIS(总览) #include <sys/socket.h> #include <sys/un.h> unix_socket = socket(PF_UNIX, t ...
- QT开发资料
QT开发入门资料 https://tmr.js.org/p/cc37608/ QT学习之路: https://www.devbean.net/
- 物理像素,逻辑像素,解决1px的问题
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- 转 直接在浏览器运行Python代码
到这个链接将代码下载到本地,然后打开cmd,使用python运行此文件,然后不要关闭窗口: https://raw.githubusercontent.com/michaelliao/learn-py ...
- 3年A班,从现在起大家都是人质-观后感
花了2天时间观看了由小室直子.铃木勇马.水野格导演,武藤将吾编剧的3年A班日剧. 这部剧我觉得很擅长用对比的手法,将一个受欢迎的老师人前人后强烈对比,一群外表成熟,内心却始终还是孩子气的学生对比,也将 ...
- thinkphp 模型调试
调试执行的SQL语句 在模型操作中 ,为了更好的查明错误,经常需要查看下最近使用的SQL语句,我们可以用getLastsql方法来输出上次执行的sql语句.例如: $User = M("Us ...