标签:gif ioc maven tca import list spring div col
spring的java配置方式是通过@configuration和@Bean这两个注解实现的
1.configuration作用在类上,相当于一个xml配置问及那
2.Bean作用于方法上,相当于xml配置中的<bean>
使用java配置方式,并实现了spring IOC功能
步骤
1. pom中导入maven依赖
2. 创建bean对象
package cn.itcast.spring; public class User { private String userName; private String passwd; private Integer age; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getPasswd() { return passwd; } public void setPasswd(String passwd) { this.passwd = passwd; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } }
3.编辑DAO层用于模拟与数据库层交互
package cn.itcast.spring; import java.util.ArrayList; import java.util.List; public class UserDAO { public List<User> queryUser() { List<User> userList = new ArrayList<User>(); for (int i = 0; i < 3; i++) { User user = new User(); user.setAge(i + 2); user.setPasswd("passwd" + i); user.setUserName("username" + i); userList.add(user); } return userList; } }
4.编写Service层用于实现与bean对象的业务逻辑
标签:gif ioc maven tca import list spring div col
原文地址:https://www.cnblogs.com/yanfeiguo1011/p/11456452.html