Spring 实际使用:配置文件

版权声明:转载请随意! https://blog.csdn.net/qq_41723615/article/details/89191002

整个Spring的核心就是一个配置文件(增加了Annotation),所以只有将表达式应用在配置文件上才会特别的有意义.

范例:利用配置文件编写表达式应用

<bean id="str" class="java.lang.String">
    <constructor-arg value="HELLOWORLD"/>
</bean>
<bean id="msg" class="com.jcn.demo.Message">
    <property name="info" value="#str.substring(0,5) + 'jcn'" />
</bean>

范例:测试本程序

public class TestMessage {

	public static void main(String[] args) throws NoSuchMethodException, SecurityException {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		Message message = ctx.getBean("msg",Message.class);
		System.out.println(message.getInfo());
	}
}

输出结果:

#str.substring(0,5) + 'jcn'

可以发现所有的处理都是围绕字符串进行的,但是后面有表达式的支持。

总结

1.Spring的字符串支持的确是最好的,利用表达式可以大量简化代码的编写。

2.Spring的核心理念就在于利用字符串来解决一切的程序开发问题。

猜你喜欢

转载自blog.csdn.net/qq_41723615/article/details/89191002