员工管理案例--web三层架构-分层解耦-IOC&DI
This commit is contained in:
@@ -5,6 +5,8 @@ import com.inmind.pojo.Result;
|
||||
import com.inmind.service.EmpService;
|
||||
import com.inmind.service.impl.EmpServiceImplA;
|
||||
import com.inmind.utils.XmlParserUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -12,36 +14,10 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class EmpController {
|
||||
private EmpService empService = new EmpServiceImplA();
|
||||
|
||||
/*@RequestMapping("/listEmp")
|
||||
public Result listEmp(){
|
||||
//1.加载并解析emp.xml
|
||||
//绝对据路径
|
||||
// String file = "D:\\workspace_idea\\inmind_web_project250913\\springboot-web-req-resp\\src\\main\\resources\\emp.xml";
|
||||
String file = this.getClass().getClassLoader().getResource("emp.xml").getFile();
|
||||
List<Emp> emps = XmlParserUtils.parse(file, Emp.class);
|
||||
@Autowired //运行时,IOC容器会提供该类型的bean对象,并赋值给该变量---依赖注入
|
||||
private EmpService empService;
|
||||
|
||||
//2.对数据进行转换处理
|
||||
emps.stream().forEach(emp->{
|
||||
//处理性别
|
||||
if (emp.getGender().equals("1")) {
|
||||
emp.setGender("男");
|
||||
}else{
|
||||
emp.setGender("女");
|
||||
}
|
||||
//处理职务
|
||||
if (emp.getJob().equals("1")) {
|
||||
emp.setJob("班主任");
|
||||
} else if ("2".equals(emp.getJob())) {
|
||||
emp.setJob("讲师");
|
||||
} else {
|
||||
emp.setJob("辅导员");
|
||||
}
|
||||
});
|
||||
//3.响应员工数据集合
|
||||
return Result.success(emps);
|
||||
}*/
|
||||
|
||||
@RequestMapping("/listEmp")
|
||||
public Result listEmp(){
|
||||
|
@@ -3,9 +3,13 @@ package com.inmind.dao.impl;
|
||||
import com.inmind.dao.EmpDao;
|
||||
import com.inmind.pojo.Emp;
|
||||
import com.inmind.utils.XmlParserUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
//Dao层数据访问的操作
|
||||
//@Component
|
||||
@Repository
|
||||
public class EmpDaoImplA implements EmpDao {
|
||||
@Override
|
||||
public List<Emp> listEmp() {
|
||||
|
@@ -4,11 +4,17 @@ import com.inmind.dao.EmpDao;
|
||||
import com.inmind.dao.impl.EmpDaoImplA;
|
||||
import com.inmind.pojo.Emp;
|
||||
import com.inmind.service.EmpService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@Component //将当前类交给IOC容器管理,成为IOC容器的bean--控制反转
|
||||
@Service
|
||||
public class EmpServiceImplA implements EmpService {
|
||||
private EmpDao empDao = new EmpDaoImplA();
|
||||
@Autowired
|
||||
private EmpDao empDao;
|
||||
|
||||
@Override
|
||||
public List<Emp> listEmp() {
|
||||
|
Reference in New Issue
Block a user