📄 adminserviceimpl.java
字号:
package limq.spring.service;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.*;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.Criteria;
import net.sf.hibernate.expression.*;
import net.sf.hibernate.Query;
import limq.hibernate.dao.*;
import limq.hibernate.vo.*;
import limq.common.*;
public class AdminServiceImpl implements IAdminService{
private Logger log = Logger.getLogger(this.getClass());
private IStudents studentsDao;
private ICourses coursesDao;
private IClasses classesDao;
private IDepartment departmentsdao;
private IAdmin adminDao;
private ITeachers teachersDao;
/**
* 验证用户名密码
*
* @param username
* @param password
*/
public boolean validate(String username, String password) {
String password2 = adminDao.getPasswordFromUsername(username);
if (password.equals(password2))
return true;
else
return false;
}
public Department[] getAllDepartment(){
return (Department[])departmentsdao.LoadAll(Department.class).toArray(new Department[0]);
}
public Courses[] getAllCourses() {
return (Courses[]) coursesDao.LoadAll(Courses.class).toArray(new Courses[0]);
}
public Students[] getAllStudents(){
return (Students[])studentsDao.LoadAll(Students.class).toArray(new Students[0]);
}
public Students[] getStudentsFromClass(Integer id) {
Classes clazz = (Classes) classesDao.loadByKey(Classes.class, "id", id);
return (Students[]) clazz.getStudents().toArray(new Students[0]);
}
public Students getStudentsById(Integer id){
return (Students)studentsDao.getByPk(Students.class,id);
}
public Department getDepartmentById(Integer id){
return(Department)departmentsdao.getByPk(Department.class,id);
}
public void insertStudent(String username,String password,String address,String email,Integer phone,Integer department){
Students stu = new Students();
Contact con = new Contact();
Department dep = (Department)departmentsdao.getByPk(Department.class,department);
stu.setContact(con);
con.setStudent(stu);
stu.setName(username);
stu.setPassword(password);
stu.setDepartment(dep);
stu.setScore(new Double(0));
dep.getStudents().add(stu);
con.setAddress(address);
con.setEmail(email);
con.setPhone(phone);
studentsDao.create(stu);
}
public void removeStudent(Integer stu_id) throws Exception{
Students stu=(Students)studentsDao.getByPk(Students.class,stu_id);
studentsDao.delete(stu);
}
public void updateStudent(Students stu,Contact con,Department department){
stu.setContact(con);
stu.setDepartment(department);
}
/**
* @return 返回 adminDao。
*/
public IAdmin getAdminDao() {
return adminDao;
}
/**
* @param adminDao 要设置的 adminDao。
*/
public void setAdminDao(IAdmin adminDao) {
this.adminDao = adminDao;
}
/**
* @return 返回 classesDao。
*/
public IClasses getClassesDao() {
return classesDao;
}
/**
* @param classesDao 要设置的 classesDao。
*/
public void setClassesDao(IClasses classesDao) {
this.classesDao = classesDao;
}
/**
* @return 返回 coursesDao。
*/
public ICourses getCoursesDao() {
return coursesDao;
}
/**
* @param coursesDao 要设置的 coursesDao。
*/
public void setCoursesDao(ICourses coursesDao) {
this.coursesDao = coursesDao;
}
/**
* @return 返回 departmentsdao。
*/
public IDepartment getDepartmentsdao() {
return departmentsdao;
}
/**
* @param departmentsdao 要设置的 departmentsdao。
*/
public void setDepartmentsdao(IDepartment departmentsdao) {
this.departmentsdao = departmentsdao;
}
/**
* @return 返回 studentsDao。
*/
public IStudents getStudentsDao() {
return studentsDao;
}
/**
* @param studentsDao 要设置的 studentsDao。
*/
public void setStudentsDao(IStudents studentsDao) {
this.studentsDao = studentsDao;
}
/**
* @return 返回 teachersDao。
*/
public ITeachers getTeachersDao() {
return teachersDao;
}
/**
* @param teachersDao 要设置的 teachersDao。
*/
public void setTeachersDao(ITeachers teachersDao) {
this.teachersDao = teachersDao;
}
public static void main(String[] arg) throws Exception {
BasicConfigurator.configure();
ApplicationContext context = new ClassPathXmlApplicationContext(
"applications-service.xml");
IAdminService admindao = (IAdminService) context
.getBean("adminManager");
Department[] ds= admindao.getAllDepartment();
for(int i=0;i<ds.length;i++){
Department dep = ds[i];
System.out.println(dep.getName());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -