mybatis--快速入门
This commit is contained in:
@@ -2,6 +2,7 @@ package com.inmind;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringbootWebReqRespApplication {
|
||||
|
||||
@@ -6,16 +6,22 @@ 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.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class EmpController {
|
||||
|
||||
@Autowired //运行时,IOC容器会提供该类型的bean对象,并赋值给该变量---依赖注入
|
||||
/*@Autowired //运行时,IOC容器会提供该类型的bean对象,并赋值给该变量---依赖注入
|
||||
@Qualifier("empServiceImplB")//当依赖注入EmpService类型的bean对象时,优先使用@Qualifier书写的bean对象名称对应的对象
|
||||
private EmpService empService;*/
|
||||
|
||||
@Resource(name = "empServiceImplA")
|
||||
private EmpService empService;
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ 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;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package com.inmind.service.impl;
|
||||
|
||||
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;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//@Component //将当前类交给IOC容器管理,成为IOC容器的bean--控制反转
|
||||
@Service
|
||||
//@Primary//当依赖注入EmpService类型的bean对象时,优先使用EmpServiceImplB
|
||||
public class EmpServiceImplB implements EmpService {
|
||||
@Autowired
|
||||
private EmpDao empDao;
|
||||
|
||||
@Override
|
||||
public List<Emp> listEmp() {
|
||||
//业务层从dao层获取数据
|
||||
List<Emp> emps = empDao.listEmp();
|
||||
|
||||
//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("辅导员");
|
||||
}
|
||||
});
|
||||
return emps;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user