81,092
社区成员
发帖
与我相关
我的任务
分享
[code=text]package com.hp.exa.hibernate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="student")
public class Student{
private String studentID;
private String password;
private String studentName;
private int result;
private String sclass;
@Id
@GeneratedValue
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
public String getSclass() {
return sclass;
}
public void setSclass(String sclass) {
this.sclass = sclass;
}
}
[/code]package com.hp.exa.hibernate;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="teacher")
public class Teacher{
private String teacherID;
private String password;
@Id
@GeneratedValue
public String getTeacherID() {
return teacherID;
}
public void setTeacherID(String teacherID) {
this.teacherID = teacherID;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
package com.hp.exa.action;
import com.hp.exa.dao.LoginDao;
import com.hp.exa.dao.impl.LoginDaoImpl;
import com.hp.exa.hibernate.Student;
import com.hp.exa.hibernate.Teacher;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class LoginAction extends ActionSupport implements ModelDriven<Student>{
/**
*
*/
private static final long serialVersionUID = 1L;
private Teacher teacher;
private Student student;
private String role;
public String execute() {
if ("student".equals(role)) {
LoginDao logindao = new LoginDaoImpl();
if (logindao.studentlogin(student)) {
return "studentsuccess";
} else {
return ERROR;
}
}else if("teacher".equals(role)){
LoginDao logindao=new LoginDaoImpl();
if(logindao.teacherlogin(teacher)){
return "teachersuccess";
}else{
return ERROR;
}
}
return role;
}
@Override
public Student getModel() {
// TODO Auto-generated method stub
if (student == null) {
student = new Student();
}
return student;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
}
package com.hp.exa.hibernate;
public class Login {
private Student student;
private Teacher teacher;
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public Teacher getTeacher() {
return teacher;
}
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}
}