Search in sources :

Example 1 with User

use of com.zsm.ssh.model.User in project Resource by lovelifeming.

the class UserAction method execute.

// @Action(value="login")
@Action(value = "login", results = { @Result(name = "success", location = "/success.jsp", params = { "resultJson", "resultJson" }), @Result(name = "error", location = "/error.jsp") })
public String execute() throws Exception {
    HttpServletResponse response = ServletActionContext.getResponse();
    HttpServletRequest request = ServletActionContext.getRequest();
    JSONObject result = new JSONObject();
    User user = userService.getByName(username);
    result.put("user", user);
    if (user != null && user.getUser_name().equals(username) && user.getPassword().equals(password)) {
        result.put("message", "登录成功");
        result.put("status", "true");
        resultJson = result.toString();
        request.setAttribute("resultJson", resultJson);
        writeResponseData(request, response, result);
        return "success";
    }
    result.put("message", "登录失败");
    result.put("status", "false");
    resultJson = result.toString();
    writeResponseData(request, response, result);
    return "error";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.zsm.ssh.model.User) JSONObject(net.sf.json.JSONObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) Action(org.apache.struts2.convention.annotation.Action)

Example 2 with User

use of com.zsm.ssh.model.User in project Resource by lovelifeming.

the class UserDaoImpl method getByName.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public User getByName(String name) {
    Session session = sessionFactory.getCurrentSession();
    // 根据id查询,结果返回 User.class
    User user = (User) session.get(User.class, 2);
    // 将所有的数据查询出来并放到List集合里 User是表对应的实例名称
    List users = session.createQuery("from User where user_name='" + name + "'").list();
    return (User) users.get(0);
}
Also used : User(com.zsm.ssh.model.User) List(java.util.List) Session(org.hibernate.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with User

use of com.zsm.ssh.model.User in project Resource by lovelifeming.

the class UserDaoImplTest method saveOrUpdateEntity.

@Test
public void saveOrUpdateEntity() throws Exception {
    User user = getUser();
    user.setId(10);
    userDao.saveOrUpdateEntity(user);
}
Also used : User(com.zsm.ssh.model.User) Test(org.junit.Test)

Example 4 with User

use of com.zsm.ssh.model.User in project Resource by lovelifeming.

the class UserDaoImplTest method getByNo.

@Test
public void getByNo() throws Exception {
    User user = userDao.getByNo("114");
    Assert.assertEquals("李元芳", user.getUser_name());
}
Also used : User(com.zsm.ssh.model.User) Test(org.junit.Test)

Example 5 with User

use of com.zsm.ssh.model.User in project Resource by lovelifeming.

the class UserDaoImpl method findAllUser.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public List<User> findAllUser() {
    Session session = sessionFactory.openSession();
    // 将所有的数据查询出来并放到List集合里 User是表对应的实例名称
    List<User> list = session.createQuery("from User").list();
    session.close();
    return list;
}
Also used : User(com.zsm.ssh.model.User) Session(org.hibernate.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.zsm.ssh.model.User)12 Test (org.junit.Test)6 Session (org.hibernate.Session)4 Transactional (org.springframework.transaction.annotation.Transactional)4 List (java.util.List)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 JSONObject (net.sf.json.JSONObject)1 Action (org.apache.struts2.convention.annotation.Action)1