javaEEday05-分层解耦-IOC&DI-入门-2
This commit is contained in:
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Component //将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转
|
//@Component //将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转
|
||||||
public class EmpServiceImplA implements EmpService {
|
public class EmpServiceImplA implements EmpService {
|
||||||
//设置一个dao的成员变量
|
//设置一个dao的成员变量
|
||||||
@Autowired//运行时,IOC容器会提供该类型的bean对象,并赋值给该变量----依赖注入
|
@Autowired//运行时,IOC容器会提供该类型的bean对象,并赋值给该变量----依赖注入
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.inmind.service.impl;
|
||||||
|
|
||||||
|
import com.inmind.dao.EmpDao;
|
||||||
|
import com.inmind.pojo.Emp;
|
||||||
|
import com.inmind.service.EmpService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component //将当前类交给IOC容器管理,让它称为IOC容器中的bean对象---IOC控制反转
|
||||||
|
public class EmpServiceImplB implements EmpService {
|
||||||
|
//设置一个dao的成员变量
|
||||||
|
@Autowired//运行时,IOC容器会提供该类型的bean对象,并赋值给该变量----依赖注入
|
||||||
|
private EmpDao empDao ;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Emp> listEmp() {
|
||||||
|
//调用dao层的功能,获取员工信息即可
|
||||||
|
List<Emp> emps = empDao.listEmp();
|
||||||
|
|
||||||
|
//逻辑处理
|
||||||
|
//2.对数据进行处理优化(处理性别,处理职位)
|
||||||
|
emps.stream().forEach(emp -> {
|
||||||
|
String gender = emp.getGender();
|
||||||
|
//处理 gender 1:男 2:女
|
||||||
|
if (gender.equals("1")) {
|
||||||
|
emp.setGender("男士");
|
||||||
|
} else {
|
||||||
|
emp.setGender("女士");
|
||||||
|
}
|
||||||
|
|
||||||
|
//处理job- 1:讲师 2:班主任 3:就业指导
|
||||||
|
String job = emp.getJob();
|
||||||
|
if ("1".equals(job)) {
|
||||||
|
emp.setJob("讲师");
|
||||||
|
} else if ("2".equals(job)) {
|
||||||
|
emp.setJob("班主任");
|
||||||
|
}else if ("3".equals(job)) {
|
||||||
|
emp.setJob("就业指导");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return emps;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user