年会小结

年会小结

  • hibernate:是一个ORM的持久层框架,不用直接操作sql语句,对实体类操作就能达到对数据库的修改。

  • query:

    • 1
      2
      3
      4
      5
      6
      7
      public void updateMoney(int sort, double money) {
      String hql = "update MoneyDistribution set money=? where sort=?";
      Query query = getSession().createQuery(hql);
      query.setParameter(0, money);
      query.setParameter(1, sort);
      int update = query.executeUpdate();
      }
    • 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      public double getSumAmountByReturnMoney1(int id,String status) {
      double sum = 0.00;

      String hql = " select sum(money) from MoneyDistribution as distribution where distribution.redGift.id = :id and distribution.receiveStatus = :receiveStatus";
      Object object = getSession().createQuery(hql).setParameter("id", id).setParameter("receiveStatus",status).uniqueResult();
      if(object!=null)
      sum = (double)object;

      return sum;
      }
    • 接收hql语句。

  • Detachedcriteria

    • 1
      2
      3
      4
      5
      6
      7
      public List<MoneyDistribution> getMoneyDistributionById(int lastId) {
      DetachedCriteria detachedCriteria = DetachedCriteria.forClass(MoneyDistribution.class);
      detachedCriteria.add(Restrictions.eq("redGift.id", lastId));

      List<MoneyDistribution> moneyDistributions = detachedCriteria.getExecutableCriteria(getSession()).list();
      return moneyDistributions;
      }
    • 1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      public List<MoneyDistribution> getMoneyDistributionById(int lastId, int pageSize, RedGift redGift) {
      DetachedCriteria detachedCriteria = DetachedCriteria.forClass(MoneyDistribution.class);
      detachedCriteria.add(Restrictions.eq("redGift", redGift));
      detachedCriteria.add(Restrictions.eq("receiveStatus", EnumReceiveStatus.RECEIVED.getCode()));
      detachedCriteria.add(Restrictions.gt("id", lastId));

      List<MoneyDistribution> moneyDistributions = detachedCriteria.getExecutableCriteria(getSession()).list();
      if (moneyDistributions.size() > pageSize) {
      moneyDistributions = moneyDistributions.subList(0, pageSize);
      }
      return moneyDistributions;
      }
-------------The End-------------
0%