SSH学习笔记三——spring环境配置(最后有strut2+spring框架整合 实现微信小程序前后台通信)
2018-08-17 00:09
609 查看
spring可以用来注入属性实现反转控制,把控制权从class文件中脱离出来。
1.导入spring所需的jar包
2、编写一个简单的pojo类。代码如下:
[code]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。代码如下:
[code]<?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、编写一个测试类进行测试。代码如下:
[code]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://www.geek-share.com/detail/2745592316.html
阅读更多相关文章推荐
- SSH学习笔记之关于struts-spring-hibernate整合配置问
- 微信小程序开发(一)——使用ssh(struts2+hibernate+spring)框架实现后台与微信前台进行通信
- SSH整合学习笔记之spring与hibernate简单整合.doc
- spring与quart整合实现任务调度_学习笔记
- PCL学习笔记(1):pcl1.6.0+vs2010环境配置以及第一个pcl程序
- 【SSH学习笔记】整合spring3-struts2的小项目(三)
- 【Linux学习】配置环境:实现【VirtualBox + ubuntu】+【开启ssh服务】+【putty远程连接到虚拟机】
- SSH:Spring框架(利用注解实现spring基本配置详解)
- 【SSH学习笔记】—从配置Struts1环境到简单实例
- Strut、Spring、Hibernate如何实现资源整合(SSH)呢?
- 菜鸟Java学习笔记02--配置JDK环境变量的目的和HelloJava程序
- Spring学习笔记 使用XML配置实现Bean的auto-wiring (自动绑定)
- 【Spring学习笔记-2】Myeclipse下第一个Spring程序-通过ClassPathXmlApplicationContext加载配置文件
- Spring4学习笔记-Spring4整合Struts2(基于配置文件的方式)
- SSH整合学习笔记之spring与hibernate整合(二)--C3P0
- 【SSH学习笔记】整合spring3-struts2的小项目(二)
- Java学习笔记(一)------服务器&客户端一对一通信小程序实现(TCP)
- 【SSH学习笔记】整合spring3-hibernate的小项目(一)
- WebService-CXF和spring整合实现webservice案例(Spring配置注解环境)
- 【SSH学习笔记】整合spring3-struts2的小项目(四)