Spring2.5+Struts1.3.8+JPA(Hibernate实现)整合之四

转载请注明:来自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层代码编写完毕,下一篇修改配置文件并进行整合后的单元测试。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值