发表于: 2018-03-21 22:22:58
1 654
今天完成的事情:(
1.今天安装学习了spring. 操作了注入对象和注解方式 了解了ioc和di的概念
IOC指反转控制 是spring的基础。简单的说就是创建对象由以前的程序员自己new构造方法来调用,变成了交由spring创建对象。
好比管理了你的资料 需要的时候直接拿
DI依赖注入 就是拿到对象的属性,已经被注入相关值
注解方式:
首先是xml配置文件添加
<context:component-scan base-package="spring" />//告诉Sping bean都放在Spring这个包下
在
@Component("q") //表面此类是bean
public class Product {
private int id;
private String name="product 1"; //因为配置在此类上。所以属性初始化放在属性声明上进行
@Autowired //@Autowired最终是根据类型来查找和装配元素的
private Category category;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
}
然后测试。
import mybatis.jopo.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring.Category;
import spring.Product;
public class TestSpring {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "applicationContext.xml" });
Product q = (Product) context.getBean("q");
System.out.println(q.getName());
}}
得到结果product 1
2.链接了JdbcTemplate 并且进行了删查增改
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property></bean>
然后我发现只要有一个类 中 带有
@Override
public String toString() {
return "???“;
}
就可以运行了
3.junit的安装和单元测试
4.把日志转成Debuf 模式 进行了调试,学会了查看但不执行时的变量时
明天计划的事情:(明天查漏吧 复习下之前学的内容 补一下基础)
遇到的问题:(1。封包的详细函数逻辑)
收获:(今天收获还是有的 还需要好好补补基础
评论