小白文章之---Spring表达式(SpEl)获取对象值
2020-01-15 01:22
453 查看
创建实体类
创建一个类用于返回实体类的值
@Component public class AccountSpEl { @Bean("test")//使用时通过“spel”调用 public Account spELAccount(){ //创建并返回对象 return new Account("admin","admin"); } }创建一个类用于获取实体类对象的值
@Component("spElView") public class SpElView { //获取容器中名字为test的值,并将值赋值给定义的变量 @Value("#{test.name}") private String name; @Value("#{test.password}") private String password; public void input(){ System.out.println(name + ":" + password); } }测试
@Configuration//配置spring容器 @ComponentScan("com.xuetang9.t8.spring")//扫描组件 public class App { public static void main( String[] args ) { //创建容器对象,扫描容器中的组件,即Component和Bean ApplicationContext ctx = new AnnotationConfigApplicationContext(App.class); SpElView spElView = ctx.getBean("spElView", SpElView.class); spElView.input(); } }
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 使用SpEL表达式来获取SpringData Jpa在更新数据时传递的对象参数的属性
- 【spring boot】SpringBoot初学(2.2)– SpEL表达式读取properties属性到Java对象
- 静态类获取Spring容器对象
- Spring3表达式语言(SpEL)的预定义变量
- ajax传值给spring后台(json),参数自动转换为对象,controller中用@RequestBody 获取
- Spring 创建对象的问题,不同构造方法创建对象,使用工厂类类获取对象、单例或多例、延迟创建问题
- Spring 表达式语言 (Spring Expression Language) SpEL
- spring aop获取目标对象的方法对象(包括方法上的注解)
- Spring表达式语言:SpEL
- Spring 表达式语言 (Spring Expression Language) SpEL
- spring接口 BeanFactoryAware,动态获取IOC容器里面的对象(多例)
- spring aop获取目标对象的方法对象(包括方法上的注解)
- 从头认识Spring-1.14 SpEl表达式(1)-简介与嵌入值
- 【第五章】Spring表达式语言 之 5.1 概述 5.2 SpEL基础 ——跟我学spring3
- 在servlet中获取spring Bean对象
- 【第五章】Spring表达式语言 之 5.3 SpEL语法 ——跟我学spring3
- 【第五章】Spring表达式语言 之 5.1 概述 5.2 SpEL基础 ——跟我学spring3
- Spring的SpEL表达式标准简单使用
- 在web容器中获取spring容器中的bean对象
- Servlet中获取spring bean的管理对象