Spring 框架的搭建及测试
1、项目结构如下:
2、com.sxl.pojos==》Student.java
package com.sxl.pojos; public class Student {
private int sid;
private String name;
private String pass;
public int getSid() {
return sid;
}
public void setSid(int sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
}
3、com.sxl.dao==》StudentDao.java
package com.sxl.dao; import com.sxl.pojos.Student; public class StudentDao { public boolean addStudent(Student s) {
System.out.println("添加学生啊:"+s.getSid()+";"+s.getName()+";"+s.getPass());
return false;
}
}
4、com.sxl.service==》StudentService.java
package com.sxl.service; import com.sxl.dao.StudentDao;
import com.sxl.pojos.Student; public class StudentService {
private StudentDao mydao;
public StudentService() {
//dao=new StudentDao(); } public boolean addUser(Student stu) {
mydao.addStudent(stu);
return false;
} //IOC注入:1.set方式。2.构造函数方式
public StudentDao getMydao() {
return mydao;
} public void setMydao(StudentDao mydao) {
this.mydao = mydao;
}
}
5、com.sxl.tests==》TestSpring.java
package com.sxl.tests;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.sxl.pojos.*;
import com.sxl.service.StudentService; public class TestSpring { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml"); Student s=(Student) context.getBean("stu");
s.setSid(1);
s.setName("aaa");
s.setPass("123"); StudentService ss=(StudentService) context.getBean("service");
ss.addUser(s); Student s2=(Student) context.getBean("stu");
s2.setSid(2);
s2.setName("vvv");
s2.setPass("123"); System.out.println(s.getSid()+";"+s.getName()+","+s.getPass());
System.out.println(s2.getSid()+";"+s2.getName()+","+s2.getPass());
}
}
6、配置文件:applicationContext.xml
<?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.0.xsd"> <bean id="stu" class="com.sxl.pojos.Student" scope="prototype"></bean> <bean id="dao" class="com.sxl.dao.StudentDao"></bean> <bean id="service" class="com.sxl.service.StudentService">
<property name="mydao" ref="dao"></property>
</bean>
</beans>
7、测试结果:
Spring 框架的搭建及测试的更多相关文章
- Spring框架学习-搭建第一个Spring项目
步骤一:下载Spring开发包. 官网:https://spring.io/ 下载地址:https://repo.spring.io/libs-release-local/org/ ...
- 【Spring】浅析Spring框架的搭建
c目录结构: // contents structure [-] Spring是什么 搭建Spring框架 简单Demo 1,建立User类 2,建立Test类 3,建立ApplicationCont ...
- SSM框架的搭建与测试
关于框架的搭建无非就是 框架所依赖的jar包,然后就是关于各个框架的配置文件: 下面我们来看下不同层的依赖的jar包以及各个配置文件: 首先pojo这一层只需要依赖parent聚合工程 mapper层 ...
- 【Spring】Spring之浅析Spring框架的搭建
Spring是什么 Spring是一个开源的容器框架,用于配置bean并且维护bean之间关系的.其主要的思想就是IOC(Inversion Of Control,控制反转)或者称作DI(Depend ...
- Spring框架环境搭建
环境要求:jdk 1.7 及以上.Spring版本:4.3.2 1.建立普通的java 工程 2.新建lib目录,并将一下5个核心jar包拷贝过来,并加入classpath中 下载地址: http: ...
- SSH框架的搭建和测试(Spring + Struts2 + Hibernate)
SSH框架实现了视图.控制器.和模型的彻底分离,同时还实现了业务逻辑层与持久层的分离. Spring实现了MVC中的 Controller的功能,Struts实现Web视图的功能,Hibernate则 ...
- SSM框架的搭建和测试(Spring+Spring MVC+MyBatis)
Spring MVC:MVC框架,通过Model-View-Controller模式很好的将数据,业务与展现进行分离. MyBatis:数据持久层框架 我这里使用的是MyEclipse 2016 CI ...
- (01)hibernate框架环境搭建及测试
---恢复内容开始--- 1.创建javaweb项目 2.导包 hibernate包 hibernate\lib\required\*.jar 数据库驱动包 mysql-connector-java- ...
- Spring环境的搭建与测试 (spring2.5.6)
这里是采用的视频里面的spring版本 下载spring2.5.6, 然后进行解压缩,在解压目录中找到下面jar文件,拷贝到类路径下 dist\spring.jar lib\jakarta-commo ...
随机推荐
- 2.1(java编程思想笔记)位移操作
java位移操作主要有两种: 有符号位移:有符号位移会保留原有数字正负性,即正数依然是正数,负数依然是负数. 有符号位左移时,低位补0. 有符号右移时:当数字为正数,高位补0.当数字为负时高位补1. ...
- HTTP模块理解(二)
这是我在写,用express+ajax+swig来做一个简单的应用的时候,遇到的问题.还是不太理解http模块. 后来在网上看到云栖社区的一篇<Node.js之HTTP请求与响应>,这里做 ...
- Delphi 中ASSERT用法
http://blog.csdn.net/dongyonggan/article/details/5780979 用法:ASSERT(表达式) 如果为假,ASSERT会产生一个EASSERTIONFA ...
- Learning Note: SQL Server VS Oracle–Database architecture
http://www.sqlpanda.com/2013/07/learning-note-sql-server-vs.html This is my learning note base on t ...
- mysql的锁定问题
1.锁定这个问题,是mysql自动产生的,不用程序猿自己加锁 答:默认情况下,档执行insert/update操作时,mysql会自动进行表锁定.从而此时读取操作只能等待. 2.mysql, 需要添加 ...
- 通过pl/sql计算程序的运行时间
在sqlplus中运行sql语句或者pl/sql的时候如果需要统计运行的时间,只需要开启set timing on选项即可. SQL> set timing onSQL>SQL> s ...
- CSS margin-top 属性
1.margin-top 属性设置元素的上外边距. 注意:允许使用负值. 2.html 文件 <html> <head> <style type="text/c ...
- docker部署golang+redis聊天室
博客地址:http://www.niu12.com/article/7#####1.项目源码: https://github.com/ZQCard/webchat#####2.项目构成 websock ...
- Cannot generate SSPI context
请在参考如下文章前,重启服务器解决! 相信我 没错的! http://support.microsoft.com/kb/811889
- ISP图像调试工程师——对比度增强(熟悉图像预处理和后处理技术)
经典对比度增强算法: http://blog.csdn.net/ebowtang/article/details/38236441