(服务器端)如何从MarkLogic检索数据并一次分页几个

时间:2017-10-30 04:08:38

标签: angularjs typescript pagination marklogic

我的目标是每次点击" next"从db中检索接下来的10个项目。按钮。

因此,我不想在数据库中检索100条记录,这可能会滞后于系统,我只想一次检索10条记录。

以下是我所做的事情的片段,不知道我还缺少什么......

在resource.java

Dim LabelList As List(Of Label)


Sub LoadSumLabel()
    LabelList = New List(Of Label)
    For x = 1 To 12
        Dim NewLabel As New Label
        With NewLabel
            .Name = DateAndTime.MonthName(x)
            .Text = "0"
            .AutoSize = True
            .Left = 10
            .Top = 10 + (LabelList.Count * NewLabel.Height)
        End With
        LabelList.Add(NewLabel)
        Me.Controls.Add(LabelList.Item(LabelList.Count - 1))
        AddHandler LabelList.Item(LabelList.Count - 1).Click, AddressOf Label_Click

        'you can create a panel and add you control to it the same way. So if you resize the form you can have the scroll bars if it doesnt fit
        'somepanel.controls(LabelList.Item(LabelList.Count - 1))
    Next
End Sub

Private Sub Label_Click(sender As Object, e As EventArgs)
    Dim thisLabel As Label = DirectCast(sender, Label)
    MsgBox(thisLabel.Name, vbOKOnly, "Result")
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
    LoadSumLabel()
End Sub

Sub RunQuery()
    connection.Open()

    query = "   SELECT SUM(Amount_income_table), MONTHNAME(Date_income_table) 
                    FROM bacci.income_table
                    where year(Date_income_table)='" & LblYear.Text & "'
                    GROUP BY MONTHNAME(Date_income_table);"
    Comand = New MySqlCommand(query, connection)
    READER = Comand.ExecuteReader
    While READER.Read
        ChartIncomeYear.Series("Incomes").Points.AddXY(READER.GetString("MONTHNAME(Date_income_table)"), READER.GetString("SUM(Amount_income_table)"))
        LabelList.Find(Function(lb As Label) lb.Name = READER.GetString("MONTHNAME(Date_income_table)")).Text = READER.GetString("SUM(Amount_income_table)")


    End While
    connection.Close()
    Catch ex As Exception
    MessageBox.Show(ex.Message)
    Finally

    connection.Dispose()
    End Try
End Sub

在component.ts

   @Autowired
   protected QueryManager queryManager;

   @RequestMapping(value = "/retrieveObjects/{page}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
   public ResponseEntity<Object[]> retrieveObjects(@PathVariable("page") String page){
      int pageNum = Integer.valueOf(page);
      int start = PAGE_SIZE_TEN * (pageNum - 1) + 1;
      SearchHandle resultsHandle = new SearchHandle(); 
      queryDef.setDirectory(DIRECTORY);
      queryManager.setPageLength(PAGE_SIZE_TEN);
      queryManager.search(queryDef, resultsHandle, start);

      return new ResponseEntity<Object[]>(handleSearch(resultsHandle), HttpStatus.OK);
   }

在component.html

this.restclient.getjson('/api/retrieveObjects/'+page)
   .subscribe(objects => {
      for(let i=0; i<objects .length; i++){
      this.objects.push(objects[i]);
      } 
   });

我有100条记录。

然而,结果只显示我前10个记录的1页,&#34; next&#34;按钮被禁用。 enter image description here

预期结果应显示前10条记录的1页,点击&#34; next&#34;按钮将调用api / retrieveObjects /来检索接下来的10条记录。

1 个答案:

答案 0 :(得分:2)

我认为你想要实现服务器端分页:

为此你必须传递一个额外的参数totalItems

{
  "count": 100, // no of total records
  "data": [    // chunk of data (in your case chunk of 10 records)
    { /* item 1 */ },
    { /* item 2 */ },
    { /* item 3 */ },
    { /*   ...  */ },
    { /* item 10 */ }
  ]
}

<div *ngFor="let object of objects.data | paginate: { itemsPerPage: 10, currentPage: p, totalItems: objects.count }">

更多信息,请阅读: http://michaelbromley.github.io/ngx-pagination/#/