Example #1
0
 public static void findList(String where, String orderby, List<Object> params, Page<Users> page) {
   TypedQuery<Users> q =
       Users.entityManager().createQuery("SELECT o FROM Users o " + where + orderby, Users.class);
   if (null != params && !params.isEmpty()) {
     int index = 1;
     for (Object param : params) {
       q.setParameter(index, param);
       index = index + 1;
     }
   }
   q.setFirstResult(page.getPageIndex() * page.getMaxResult()).setMaxResults(page.getMaxResult());
   page.setList(q.getResultList());
   TypedQuery<Long> totalQ =
       Users.entityManager().createQuery("select count(o) from Users o " + where, Long.class);
   if (null != params && !params.isEmpty()) {
     int index = 1;
     for (Object param : params) {
       totalQ.setParameter(index, param);
       index = index + 1;
     }
   }
   page.setTotalResult(totalQ.getSingleResult().intValue());
 }
Example #2
0
 @Transactional
 public static boolean AddUsers(String username, String passwd) {
   Users user = new Users();
   boolean fale = true;
   try {
     user.setUsername(username);
     String salt = UUID.randomUUID().toString();
     String passwdend = PaySign.EncoderByMd5(passwd, salt);
     user.setPasswd(passwdend);
     user.setUserid(RandomNumberGenerator.generateNumber2());
     user.setSalt(salt);
     user.setHasher("MD5");
     user.setIsActivated("否");
     user.setIsEnabled("是");
     user.setUser_type(0);
     user.setCreatedAt(new Date());
     user.persist();
   } catch (NoSuchAlgorithmException e) {
     e.printStackTrace();
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
   //
   return fale;
 }