spring Setter方法注入

package entity;

public class User {
	private String id;
	private String name;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
}

 

package dao;

public interface UserDao {
	public void saveUser();
	public void getUserById(int id);
}

 

package dao.imp;

import dao.UserDao;

public class UserDaoImp implements UserDao{

	@Override
	public void saveUser() {
		// TODO Auto-generated method stub
		System.out.println("--------save user------");
	}

	@Override
	public void getUserById(int id) {
		// TODO Auto-generated method stub
		
	}

}

 

package service;

public interface UserService {
	public void saveUser();
	public void getUserById(int id);
}

 

package service.imp;

import dao.UserDao;
import service.UserService;

public class UserServiceImp implements UserService{
	private UserDao userDao;
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public void saveUser() {
		// TODO Auto-generated method stub
		System.out.println("SAVE USER");
	}

	@Override
	public void getUserById(int id) {
		// TODO Auto-generated method stub
		
	}

}

 

package action;

import service.UserService;

public class UserAction {
private UserService userService;
public UserService getUserService() {
	return userService;
}
public void setUserService(UserService userService) {
	this.userService = userService;
}
public String saveUser(){
	userService.saveUser();
	return null;
}
}

 

<?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="userDao" class="dao.imp.UserDaoImp"></bean>
<bean id="userService" class="service.imp.UserServiceImp">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userAction" class="action.UserAction">
<property name="userService" ref="userService"></property>
</bean>
</beans>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。