Javascript 分页jquery数据表和Spring问题
我一直在尝试对用于显示某些数据的数据表进行分页。让我解释一下整个情况 首先,我有一个服务代码,可以帮助我了解所有行业:Javascript 分页jquery数据表和Spring问题,javascript,jquery,spring,pagination,datatables,Javascript,Jquery,Spring,Pagination,Datatables,我一直在尝试对用于显示某些数据的数据表进行分页。让我解释一下整个情况 首先,我有一个服务代码,可以帮助我了解所有行业: @Transactional @Override public List<IndustryModel> getBusinessNature(String acctCatName) { try { List<AcctBusinessNature> acctBusinessNatureList = acctBusinessNature
@Transactional
@Override
public List<IndustryModel> getBusinessNature(String acctCatName) {
try {
List<AcctBusinessNature> acctBusinessNatureList = acctBusinessNatureRepository
.findByAcctCategoryAcctCatName(acctCatName);
List<IndustryModel> listOfIndustries = new ArrayList<IndustryModel>();
int id = acctBusinessNatureList.size();
int idOrder = 0;
for (AcctBusinessNature BussinesNatureTmp : acctBusinessNatureList) {
if (idOrder < id) {
IndustryModel industryModel = new IndustryModel();
industryModel.setId(++idOrder);
industryModel.setIndustryId(BussinesNatureTmp.getBusNatureId());
industryModel.setIndustryInEnglish(BussinesNatureTmp.getBusNatureTitleEn());
industryModel.setIndustryInArabic(BussinesNatureTmp.getBusNatureTitleAr());
industryModel.setAddedDate(BussinesNatureTmp.getCreatedTs());
industryModel.setUserName(BussinesNatureTmp.getCreatedUser());
listOfIndustries.add(industryModel);
}
}
return listOfIndustries;
} catch (Exception e) {
throw new GeneralLookUpException(GeneralLookUpExceptionCode.GET_DOC_TYPE, e.toString());
}
}
行业
我试着在我的js中使用这样的数据表,但什么都没有发生:
$.ajax({
键入:“获取”,
url:getContextPath()+“/generalSettingIndustries”,
成功:功能(数据){
$(“#数据表”)。数据表({
“bJQueryUI”:没错,
“bSort”:错误,
“bPaginate”:对,
“sPaginationType”:“完整编号”,
“iDisplayLength”:10,
“bServerSide”:正确,
“数据”:数据,
"摧毁":对,,
“列”:[{
“数据”:“id”
}, {
“数据”:“工业英语”
}, {
“数据”:“工业阿拉伯语”
}, {
“数据”:“添加数据”
}, {
“数据”:“用户名”
} ]
});
},
错误:函数(e){
警惕(“有些事情出了差错”);
//警报(“提交失败”+JSON.stringify(e));
}
这就是我正在做的。如何在显示表后为其添加分页?尝试以下步骤:
import org.springframework.data.domain.Page;
导入org.springframework.data.domain.Pageable;
公共接口YourEntityRepository扩展
JPA阳性{
页面findAll(可分页可分页);
}
@Autowired
私人实体回购;
公共列表getYourEntityByPage(int pageNumb){
int size=8;
PageRequest=新的PageRequest(PageNum-1,大小);
返回此.convertPageToList(this.repo.findAll(请求));
}
在此,您必须将页面转换为列表
private List convertPageToList(第页){
列表项=新建ArrayList();
迭代器迭代器=page.Iterator();
while(iterator.hasNext())
items.add(iterator.next());
退货项目;
}
@RequestMapping(value = "/generalSettingIndustries", method = RequestMethod.GET)
public ModelAndView getIndustryLookUp() {
ModelAndView model = new ModelAndView("/generalSettingLookup/industryGridPartial");
List<IndustryModel> listOfIndustries = generalSettingMerchantLookUpService.getBusinessNature(Constant.MERCHANT);
IndustryModel industryModel = new IndustryModel();
model.addObject("listOfIndustries", listOfIndustries);
model.addObject("industryModel", industryModel);
return model;
}
function getIndustries() {
var csrfParameter = $("#_csrfParam").attr("content");
var csrfToken = $("#_csrf").attr("content");
var jsonParams = {};
jsonParams[csrfParameter] = csrfToken;
$.ajax({
type : "GET",
url : getContextPath() + "/generalSettingIndustries",
success : function(data) {
$("#industryGrid").html(response); });
}
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
public interface YourEntityRepository extends
JpaRespository<YourEntity,Long>{
Page<YourEntity> findAll(Pageable pageable);
}
@Autowired
private YourEntityRepository repo;
public List<YourEntity> getYourEntityByPage(int pageNumb){
int size=8;
PageRequest request=new PageRequest(pageNumb-1, size);
return this.convertPageToList(this.repo.findAll (request));
}
private List<YourEntity> convertPageToList(Page<YourEntity> page){
List<YourEntity> items=new ArrayList<YourEntity>();
Iterator<YourEntity> iterator= page.iterator();
while(iterator.hasNext())
items.add(iterator.next());
return items;
}