SSH学习笔记三——spring环境配置(最后有strut2+spring框架整合 实现微信小程序前后台通信)

spring可以用来注入属性实现反转控制,把控制权从class文件中脱离出来。

1.导入spring所需的jar包

2、编写一个简单的pojo类。代码如下:

public class SUser {
	private String name;
	private String age;
	private String pwd;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAge() {
		return age;
	}
	public void setAge(String age) {
		this.age = age;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public void information() {
		System.out.println("姓名:"+name+"年龄:"+age+"密码:"+pwd);
		
	}
	
}

3.编写配置文件applicationContext.xml。代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"  
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
    xmlns:cache="http://www.springframework.org/schema/cache"  
    xsi:schemaLocation="  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context.xsd  
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans.xsd  
    http://www.springframework.org/schema/tx  
    http://www.springframework.org/schema/tx/spring-tx.xsd  
    http://www.springframework.org/schema/jdbc  
    http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd  
    http://www.springframework.org/schema/cache  
    http://www.springframework.org/schema/cache/spring-cache-3.1.xsd  
    http://www.springframework.org/schema/aop  
    http://www.springframework.org/schema/aop/spring-aop.xsd  
    http://www.springframework.org/schema/util  
    http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/context
	http://www.springframework.org/schema/context/spring-context-3.0.xsd">  
<bean id="suser" class="dps.spring.SUser">
	<property name="name" value="小王" ></property> 
	<property name="age" value="22" ></property>
    <property name="pwd" value="123" ></property>
</bean>

</beans>

 4、编写一个测试类进行测试。代码如下:

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//读取配置文件
		ApplicationContext act=new ClassPathXmlApplicationContext("applicationContext.xml");
		//从spring容器中获取id为suser的bean
		SUser user = act.getBean("suser",SUser.class);
		user.information();
	}

}

spring+strut2框架整合:(实现微信小程序前台后台通信)https://blog.csdn.net/t554984986/article/details/81811679

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值