datatables+json+ajax以json输出和删除

直接上干货:


首先:引入datatables.js和jquery.js和bootstrap.jsp等一些文件:

如:









1.html

id aaa bbb ccc ddd eee


2.javascript


3.controller

@Override
@RequestMapping(value="tradeRecord_query",method=RequestMethod.GET)//list
@ResponseBody
public String beanList(int limit,int start,int page,HttpSession httpSession, Model m) {
	System.out.println(limit+"--->"+start+"--->"+page);
	@SuppressWarnings("unchecked")
	List list = (List) this.service.find("beanList", "TransactionTypeBean", null);
	System.out.println(start+"--->"+(start+limit)+"--->"+list.size());
	System.out.println(list.get(0).getId()+"-------->");
	List pageList=null;
	HashMap map = new HashMap();
	if(list.size()");
		
		map.put("recordsTotal", list.size());
		map.put("recordsFiltered", list.size());
		map.put("data", pageList);	
		String s = this.jsonUtil.toJson(map);
		return s;
	}
@Override
@ResponseBody
@RequestMapping(value="tradeRecord_delete",method=RequestMethod.POST)//delete
public String beanDelete(TransactionTypeBean bean, HttpSession httpSession, Model m) throws Exception {
	System.out.println(bean.getId()+"----------->");
	HashMap map = new HashMap();
	map.put("success", "success");
	try {
		service.delete(bean);
	} catch (Exception e) {
		e.printStackTrace();
	}
		String data = this.jsonUtil.toJson(map);
		return data;
	}



有什么疑问,和建议大家可以留言讨论。











你可能感兴趣的:(前端-后端)