Działam sobie pewien tutorial i zastanawia mnie jedna rzecz. Wrzuce dwie klasy i interfejs i jakby ktoś był tak miły i wyjaśnił mi :
Dlaczego w klasie StudentBean powstała zmienna
private StudentService studentService;
gdzie StudentService jest tylko interfejsm w którym są dwie metody.
Interfejs StudentService:
package pl.konrad.student.service;
import java.util.List;
import pl.konrad.student.model.Student;
public interface StudentService {
public void addStudent(Student student);
public List<Student> findAll();
}
Klasa StudentServiceImple:
package pl.konrad.student.service;
@Service("studentService")
@Transactional
public class StudentServiceImpl implements StudentService
{
@Autowired
private SessionFactory sessionFactory;
@Override
public void addStudent(Student student) {
sessionFactory.getCurrentSession().save(student);
}
@Override
public List<Student> findAll() {
return sessionFactory.getCurrentSession().createQuery("fron Student").list();
}
}
StudentBean:
package pl.konrad.beans;
import java.util.List;
import javax.faces.bean.ManagedBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import pl.konrad.student.model.Student;
import pl.konrad.student.service.StudentService;
@ManagedBean
@Scope
public class StudentBean {
@Autowired
private StudentService studentService;
private List<Student> listStudents;
public List<Student> getListStudents() {
listStudents = studentService.findAll();
return listStudents;
}
public void setListStudents(List<Student> listStudents) {
this.listStudents = listStudents;
}
}