如何在Spring数据中进行groupBy

时间:2017-01-04 14:06:37

标签: angularjs spring-data

您好我在我的项目中使用弹簧数据而我在两个字段中尝试分组,继续请求:

window.requestAnimFrame = (function() {
  return window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame ||
    window.mozRequestAnimationFrame ||
    window.oRequestAnimationFrame ||
    window.msRequestAnimationFrame ||
    function(callback, element) {
      window.setTimeout(callback, 1000 / 60);
    };
})();

SpinWheel = function(id) {

  var _this = this;

  _this.el = $('.wheel-wrapper');
  _this.speed = 0;
  _this.startTime = new Date();
  _this.items = 20;
  _this.itemsWidth = 50;
  _this.spinTime = 3000;
  _this.running = false;
  _this.motion = 20;
  _this.resultId = id;
  _this.resultOffset = null;

  _this.setup = function() {
    _this.resultOffset = _this.resultId * _this.itemsWidth;
    _this.loop();
  };

  _this.loop = function() {
    _this.running = true;
    (function gameLoop() {
      _this.update();
      //this returns the translateX to 0 once wheel width is met
      if (_this.speed >= (_this.items * _this.itemsWidth + _this.itemsWidth)) {
        _this.speed = 0;
      }
      _this.speed += _this.motion;
      if (_this.running) {
        requestAnimFrame(gameLoop);
      }
    })();
  };

  _this.update = function() {
    var now = new Date();
    _this.el.css({
      'transform': 'translateX(-' + _this.speed + 'px)'
    });
    //the key area!!
    //if the time elapsed it greater than the spin time, start the slowing down
    if (now - _this.startTime > _this.spinTime) {
        //if the x pos == winning pos && the transition speed is at it's slowest
      if (_this.speed == _this.resultOffset && _this.motion == 1) {
      //stop the animation
        _this.running = false;
        //here we increment down the slowing down
      } else if (_this.speed >= _this.resultOffset) {
        if (_this.motion == 2) {
          _this.motion = 1;
        } else if (_this.speed % _this.motion == 0 && _this.motion > 1) {
          _this.motion -= 2;
        }
      }
      return;
    }

  };


  _this.init = function() {
    _this.setup();
  };

  _this.init();

  return _this;

};
//will be passed in: 20 = number of items
var resultId = parseInt(Math.random() * 20);

var wheel = new SpinWheel(resultId);

它有效,但数据并没有按行业分组......这是它给我的东西:

@Query( "SELECT obj from Agence obj GROUP BY  obj.secteur.nomSecteur,obj.nomAgence" )
Iterable<Agence> getSecteurAgenceByPc();

我正在寻找的行为是:

{
    "status": 0,
    "data":
    [
        {
            "secteur": "Safi",
            "agence": "CTM"
        },
        {
            "secteur": "Safi",
            "agence": "Dep"
        },
        {
            "secteur": "Rabat",
            "agence": "Agdal"
        },
        {
            "secteur": "Rabat",
            "agence": "CTM"
        },
        {
            "secteur": "Essaouira",
            "agence": "CTM"
        },
        {
            "secteur": "Essaouira",
            "agence": "Gare Routiere Municipale"
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

如果您只想通过secteur尝试tou group:

&#34;从Agence obj GROUP BY obj.secteur.nomSecteur&#34;

中选择obj