package com.service;
import java.util.Scanner;
import com.dao.EmpDao;
import com.entity.Emp;
import com.util.DateUtil;
public class EmpService {
Scanner input =new Scanner(System.in);
private EmpDao empDao;
public void mainMenu(){
System.out.println("请输入员工姓名:");
String name=input.next();
System.out.println("请输入员工职位:");
String job=input.next();
System.out.println("请输入入职时间:");
String hiredate=input.next();
System.out.println("请输入薪资:");
double sal=input.nextDouble();
System.out.println("请输入奖金:");
double comm=input.nextDouble();
System.out.println("请输入部门编号:");
int deptid=input.nextInt();
Emp emp = new Emp(name, job, DateUtil.StringToDate(hiredate), sal, comm, deptid);
try {
empDao.addEmp(emp);
System.out.println("添加成功!");
} catch (Exception e) {
System.out.println("添加失败,请稍后再试!");
e.printStackTrace();
}
}
public EmpDao getEmpDao() {
return empDao;
}
public void setEmpDao(EmpDao empDao) {
this.empDao = empDao;
}
}
<?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="empDao" class="com.dao.impl.EmpDaoImpl"></bean>
<!-- 注入服务层对象 -->
<bean id="empService" class="com.service.EmpService" autowire="byName"></bean>
</beans>
刚开始找了好久都没有找出来,后来看了别人的博客,才想起来,发现自己的配置文件里少写了autowire="byName"这句话