HelloSpring
来源:互联网 发布:什么是阿里云证书 编辑:程序博客网 时间:2024/05/25 19:57
Hello 实体类
package entity;public class Hello {private String someBody;public void setSomeBody(String someBody) {this.someBody = someBody;}public String getSomeBody() {return someBody;}public void sayHi() {String say = "Hello" + someBody + "!";System.out.println(say);}}
配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"><!--id是自己随便写的,class是实体类。 property是实体类中的set方法中的名字。 value是给对象定义属性值 --><bean id="hello" class="entity.Hello"><property name="someBody" value="孟振"></property></bean></beans>
测试类
package Test;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import entity.Hello;public class test {public static void main(String[] args) {ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");Hello h=(Hello)context.getBean("hello");//hello是配置文件中的那个bean的idh.sayHi();}}
输出结果:Hello孟振!
0 0
- HelloSpring
- Spring-(1)HelloSpring
- 12.2 基于注解的 HelloSpring
- Spring从开始到精通HelloSpring
- Spring-Spring 开发环境搭建及HelloSpring
- 【Spring】HelloSpring:使用IntelliJ IDEA学习Spring
- 第一个使用spring实现hellospring的例子
- 12.3 第一个Spirng应用单词表:HelloSpring
- 我的Spring之旅(一):HelloSpring【附github源码】
- 【webpack】 模块加载器兼打包工具
- 【Java集合系列】---总体框架
- chmod
- 用C语言读取配置文件
- python win7 升级pip
- HelloSpring
- 【CCF 折点技术 水】
- 使用Node.js和MongoDB通过Mongoshin和Express.js构建JSON REST API服务器
- CSS 子元素 maigin-top 让父元素同样有效果处理
- 抽象类和接口的区别
- 把Activity当成Dialog的时候不能全屏显示 (部分手机上)
- C/C++基础整理(1)
- 12.表单与验证
- Redis键值(Key-Value)设计案例