转载请注明:来自http://blog.csdn.net/M_ChangGong/ 作者:张燕广
该篇主要编写service层代码。
在src下创建包com.zyg.ssj.service,并在该包下创建接口StudentService,该接口文件代码如下:
package com.zyg.ssj.service; import java.util.List; import com.zyg.ssj.bean.Student; import com.zyg.ssj.dao.StudentDao; public interface StudentService { /** * 保存学生信息 * @param student */ public abstract void save(Student student); /** * 根据学号删除学生信息 * @param studentId */ public abstract void delete(Integer studentId); /** * 根据学生删除学生信息 * @param studentId */ public abstract void delete(Student student); /** * 更新学生信息 * @param student */ public abstract void update(Student student); /** * 根据学号获取学生信息 * @param studentId */ public abstract Student getStudent(Integer studentId); /** * 获取全部学生信息 * @param studentId */ public abstract List<Student> getStudents(); }
在src下创建包com.zyg. ssj.service.impl,并在该包下创建接口
StudentService的实现类StudentServiceImpl,该类文件内容如下:
package com.zyg.ssj.service.impl; import java.util.List; import javax.annotation.Resource; import com.zyg.ssj.bean.Student; import com.zyg.ssj.dao.StudentDao; import com.zyg.ssj.service.StudentService; public class StudentServiceImpl implements StudentService { @Resource private StudentDao studentDao; /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#save(com.zyg.ssj.bean.Student) */ public void save(Student student){ studentDao.save(student); } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#delete(java.lang.Integer) */ public void delete(Integer studentId){ studentDao.delete(studentId); } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#delete(com.zyg.ssj.bean.Student) */ public void delete(Student student){ studentDao.delete(student); } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#update(com.zyg.ssj.bean.Student) */ public void update(Student student){ studentDao.update(student); } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#getStudent(java.lang.Integer) */ public Student getStudent(Integer studentId){ return studentDao.getStudent(studentId); } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#getStudents() */ public List<Student> getStudents(){ return studentDao.getStudents(); } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#getStudentDao() */ public StudentDao getStudentDao() { return studentDao; } /* (non-Javadoc) * @see com.zyg.ssj.service.impl.StudentService#setStudentDao(com.zyg.ssj.dao.StudentDao) */ public void setStudentDao(StudentDao studentDao) { this.studentDao = studentDao; } }
至此,service层代码编写完毕,下一篇修改配置文件并进行整合后的单元测试。