博客
关于我
spring 的IOC的依赖注入(DI)-------普通属性,集合的注入
阅读量:401 次
发布时间:2019-03-05

本文共 2773 字,大约阅读时间需要 9 分钟。

?. ??????

?Spring?????????????????????????????????application.properties?xml?????????????????Spring???bean??

??????

?????

public class UserServiceImpl implements UserService {    private String userName;    private String password;    private UserDao ud;    // ???????    public UserServiceImpl(UserDao ud) {        this.ud = ud;    }    // ??????    public UserServiceImpl() {    }    public void setUserName(String userName) {        this.userName = userName;    }    public void setPassword(String password) {        this.password = password;    }    public int addUser() {        System.out.println("uname:" + userName + "password:" + password);        return ud.addUser();    }}

?. ?????

?Spring???????????????????????List?Map?

??????

liu
jian
fu

?????

public class UserServiceImpl implements UserService {    private List
strNameList; private Map
userMap; public List
getStrNameList() { return strNameList; } public void setStrNameList(List
strNameList) { this.strNameList = strNameList; } public Map
getUserMap() { return userMap; } public void setUserMap(Map
userMap) { this.userMap = userMap; } public int addUser() { System.out.println("uname:" + userName + "password:" + password); System.out.println("strlist:" + strNameList.toString()); System.out.println("map:"); for (String key : userMap.keySet()) { System.out.println("u:" + userMap.get(key).getName() + ">>:" + userMap.get(key).getAge()); } return ud.addUser(); }}

?. ????????

?Spring????????@Autowired???ref??????????????????bean?

??????

?????

public class UserServiceImpl implements UserService {    private UserDao ud;    // ???????    public UserServiceImpl(UserDao ud) {        this.ud = ud;    }    // ??????    public UserServiceImpl() {    }    public int addUser() {        System.out.println("uname:" + userName + "password:" + password);        return ud.addUser();    }}

?????????????????????????????Spring????????????

转载地址:http://beuzz.baihongyu.com/

你可能感兴趣的文章
poj 2545 Hamming Problem
查看>>
poj 2723
查看>>
poj 2763 Housewife Wind
查看>>
Qt笔记——模型/视图MVD 文件目录浏览器软件
查看>>
POJ 2892 Tunnel Warfare(树状数组+二分)
查看>>
poj 2965 The Pilots Brothers' refrigerator-1
查看>>
poj 3026( Borg Maze BFS + Prim)
查看>>
POJ 3041 - 最大二分匹配
查看>>
POJ 3041 Asteroids(二分匹配模板题)
查看>>
Qt笔记——标准文件对话框QFileDialog
查看>>
poj 3083 Children of the Candy Corn
查看>>
POJ 3083 Children of the Candy Corn 解题报告
查看>>
POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
查看>>
Qt笔记——控件总结
查看>>
poj 3262 Protecting the Flowers 贪心
查看>>
poj 3264(简单线段树)
查看>>
Qt笔记——布局管理三件套分割窗口、停靠窗口和堆栈窗口
查看>>
poj 3277 线段树
查看>>
POJ 3349 Snowflake Snow Snowflakes
查看>>
POJ 3411 DFS
查看>>