gpt4 book ai didi

java - 我在这里缺少什么?

转载 作者:行者123 更新时间:2023-12-01 12:00:06 24 4
gpt4 key购买 nike

所以我终于解决了我的分页jquery数据表问题。但随后新的问题又出现了。它仍然加载 1000 行数据,但它没有遵循我想要的数据数量。所以我认为它在服务器端抛出隐藏变量,例如 sEchoiTotalRecordsiTotalDisplayRecords 等。我所做的是找到一个关于它的指南是 this 。我研究了文章并尝试将其整合到我的文章中。

这是集成:

对于 Controller

@RequestMapping(value = "populate/pull", method = RequestMethod.GET)
public void populatePull(HttpServletRequest request,
HttpServletResponse response) throws IOException {
JqueryDataTableModel param = DatatableParams.getParam(request);
String sEcho = param.sEcho;
int iTotalRecords=0; // total number of records (unfiltered)
int iTotalDisplayRecords; //value will be set when code filters companies by keyword
List<KspeakPull> pullList = pullServive.viewAllPull();
System.out.println("Viewing all");
iTotalDisplayRecords=pullList.size();
if(pullList.size()< param.iDisplayStart + param.iDisplayLength) {
pullList = pullList.subList(param.iDisplayStart, pullList.size());
} else {
pullList = pullList.subList(param.iDisplayStart, param.iDisplayStart + param.iDisplayLength);
}
Gson gson = new Gson();

JsonObject jsonResponse = new JsonObject();
jsonResponse.addProperty("sEcho", sEcho);
jsonResponse.addProperty("iTotalRecords", iTotalRecords);
jsonResponse.addProperty("iTotalDisplayRecords", iTotalDisplayRecords);
jsonResponse.add("aaData", gson.toJsonTree(pullList));
System.out.println(jsonResponse.toString());
response.setContentType("application/Json");
response.getWriter().print(jsonResponse.toString());

}

jQuery 表模型从指南中复制了这个,我想知道这是否是问题所在,因为他没有使用任何 getter/setter:

public class JqueryDataTableModel {

// / Request sequence number sent by DataTable, same value must be returned
// in response
public String sEcho;

// / Text used for filtering

public String sSearch;

// / Number of records that should be shown in table

public int iDisplayLength;

// / First record that should be shown(used for paging)

public int iDisplayStart;

// / Number of columns in table
public int iColumns;

// / Number of columns that are used in sorting

public int iSortingCols;

// / Index of the column that is used for sorting

public int iSortColumnIndex;

// / Sorting direction "asc" or "desc"

public String sSortDirection;

// / Comma separated list of column names

public String sColumns;
}

和数据表参数:

public class DatatableParams {

public static JqueryDataTableModel getParam(HttpServletRequest request) {
if (request.getParameter("sEcho") != null
&& request.getParameter("sEcho") != "") {
JqueryDataTableModel param = new JqueryDataTableModel();
param.sEcho = request.getParameter("sEcho");
param.sSearch = request.getParameter("sSearch");
param.sColumns = request.getParameter("sColumns");
param.iDisplayStart = Integer.parseInt(request
.getParameter("iDisplayStart"));
param.iDisplayLength = Integer.parseInt(request
.getParameter("iDisplayLength"));
param.iColumns = Integer.parseInt(request.getParameter("iColumns"));
param.iSortingCols = Integer.parseInt(request
.getParameter("iSortingCols"));
param.iSortColumnIndex = Integer.parseInt(request
.getParameter("iSortCol_0"));
param.sSortDirection = request.getParameter("sSortDir_0");
return param;
} else
return null;
}
}

在我的 JSP 中导入以下脚本:

<script src="<c:url value='/resources/jquery-1.8.3.js'/>"></script>
<script src="<c:url value='/resources/bootstrap/js/jquery.dataTables.min.js'/>"></script>
<script src="<c:url value='/resources/bootstrap/js/pull-populate.js' />"></script>
<script src="<c:url value='/resources/bootstrap/js/bootstrap.min.js' />"></script>

和我的ajax代码:

$(document).ready(function() {
$("#tablediv").hide();
$("#showTable").click(function(event){
$.get('populate/pull',function(responseJson) {
if(responseJson!=null){
$("#pulltable").DataTable({
"bServerSide": true,
"sAjaxSource": "populate/pull",
"bProcessing": true,
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"aoColumns": [
{ "mDataProp": "id" },
{ "mDataProp": "alias1" },
{ "mDataProp": "alias2" },
{ "mDataProp": "alias3" },
{ "mDataProp": "alias4" },
{ "mDataProp": "keyword" },
{ "mDataProp": "charNo" },
{ "mDataProp": "korWord" },
{ "mDataProp": "korCharNo" },
{ "mDataProp": "charTotal" },
] });
}
});
$("#tablediv").show();
}); });

运行时会导致此行出现 NullPointerException:

 String sEcho = param.sEcho;

那么,我在这里缺少什么?显然它没有收到请求。

最佳答案

&& request.getParameter("sEcho") != ""

您正在使用 != ,它将检查引用相等性,而不是值相等性(请参阅 How do I compare strings in Java? )。

由于这将为false,因此您的else将始终返回null。然后,您执行String sEcho = param.sEcho;param将为null

关于java - 我在这里缺少什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28037288/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com