HardBirch

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

时间:09-04-25 栏目:iOS移动应用开发技术 作者:张飞不张,文采横飞 评论:1 点击: 1,452 次

  该篇主要编写service层代码。

  在src下创建包com.zyg.ssj.service,并在该包下创建接口StudentService,该接口文件代码如下:

 

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,该类文件内容如下:


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

声明: 本文由( 张飞不张,文采横飞 )原创编译,转载请保留链接: Spring2.5+Struts1.3.8+JPA(Hibernate实现)整合之四

Spring2.5+Struts1.3.8+JPA(Hibernate实现)整合之四:目前有1 条留言

  1. 沙发
    zhang50027234:

    说的挺细的

    2009-04-25 09:19 [回复]

发表评论


QQ群互动

Linux系统与内核学习群:194051772

WP建站技术学习交流群:194062106

魔豆之路QR

魔豆的Linux内核之路

魔豆的Linux内核之路

优秀工程师当看优秀书籍

优秀程序员,要看优秀书!

赞助商广告

友荐云推荐