在hibernate中匹配用户名密码

时间:2017-07-12 11:01:59

标签: java mysql hibernate

我正在使用jersery框架..我想匹配用户名和密码以进行登录。怎么搭配我试过了,我无法得到任何帮助..如何在jersery框架中匹配登录页面的用户名和密码并通过hibernate从mysql中检索数据。 Entity类如下所示:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int patientId;
@Column
private String email;
@Column
private String password;
@Column
private int modifiedby;
@Column
private String modifiedon;


public int getPatientId() {
    return patientId;
}

public void setPatientId(int patientId) {
    this.patientId = patientId;
}

public String getEmail() {
    return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

public int getModifiedby() {
    return modifiedby;
}

public void setModifiedby(int modifiedby) {
    this.modifiedby = modifiedby;
}

public String getModifiedon() {
    return modifiedon;
}

public void setModifiedon(String modifiedon) {
    this.modifiedon = modifiedon;
}

这是我的控制器类:

@GET
@Produces("application/json")
public Response getallLogin() {
    LoginDAO dao = new LoginDAO();
    List register = dao.getallLogin();
    String json = new Gson().toJson(register);
    return Response.ok().entity(json.toString()).build();
}

@POST
@Path("/create")
@Consumes("application/json")
public Response addLogin(Login reg){
    reg.setPatientId(reg.getPatientId());
    reg.setEmail(reg.getEmail());
    reg.setPassword(reg.getPassword());
    reg.setModifiedon(reg.getModifiedon());
    reg.setModifiedby(reg.getModifiedby());
    LoginDAO dao = new LoginDAO();
    dao.addLogin(reg);
    return Response.ok().build();
}

这是我的DAO课程:

public List<Login> getallLogin(){
    Session session = SessionUtil.getSession();
    Query query = session.createQuery("from Login");
    List<Login> logins =  query.list();
    session.close();
    return logins;
}

public void addLogin(Login bean) {
    Session session = SessionUtil.getSession();
    Transaction tx = session.beginTransaction();
    addLogin(session, bean);
    tx.commit();
    session.close();
}

private void addLogin(Session session,Login bean){
    Login register = new Login();
    register.setPatientId(bean.getPatientId());
    register.setEmail(bean.getEmail());
    register.setPassword(bean.getPassword());
    register.setModifiedby(bean.getModifiedby());
    register.setModifiedon(bean.getModifiedon());
     session.save(register);
}

0 个答案:

没有答案