spring入门
准备资源
网盘
链接:https://pan.baidu.com/s/1VsG3HQPeERmTB2Zeqt-F4w
提取码:t8fl
解压后开始使用
C:\Users\Lenovo\Desktop\各种框架安装包\b站spring\尚硅谷框架_雷丰阳_ssm\工具
这个路径下有4个文件,其中有spring专用的eclipse
C:\Users\Lenovo\Desktop\各种框架安装包\b站spring\尚硅谷框架_雷丰阳_ssm\Spring\Spring\lib
这个路径是需要的jar,要注意如果新建java项目而不是web项目,那么将这些包导入l自己建的ib后还需要右键
下面写第一个程序
理解:对于对象spring没有new一个对象的过程,而是用bean标签向容器注册有一个对象,property标签对对象各个属性赋值
写这些代码时候很多用到akt+/自动补全
person01.java
package person;
public class person01 {
private String lastname;
private int aage;
private String email;
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public int getAage() {
return aage;
}
public void setAage(int aage) {
this.aage = aage;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "person01 [lastname=" + lastname + ", aage=" + aage + ", email=" + email + "]";
}
}
testioc.java
package persontest;
import static org.junit.Assert.*;
import org.junit.Assert.*;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import person.person01;
public class testioc {
@Test
public void test() {
//fail("Not yet implemented");
ApplicationContext ioc=new ClassPathXmlApplicationContext("hellospring01.xml");
person01 bean = (person01) ioc.getBean("per01");
System.out.print(bean);
}
}
uiui.java
package persontest;
import static org.junit.Assert.*;
import org.junit.Test;
public class uiui {
@Test
public void test() {
fail("Not yet implemented");
}
}
hellospring01.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="per01" class="person.person01">
<property name="aage" value="18"></property></bean>
</beans>