bootgrid的分页和查询界面不工作
我尝试做了一个简单的bootgrid,通过servlet将json数据传到bootgrid,虽然可以显示,但是分页功能和查询功能却不能工作,直接在表格中显示出了所有的内容
以下是我的JS
$(document).ready(function(){ $("#grid-command-buttons").bootgrid( { ajax: true, url: "/newspider/test.do", }); })
我的servlet如下:
public class AjaxServlet extends HttpServlet {
private static final long serialVersionUID = 3191586035737158373L;
public AjaxServlet() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8"); // 设置编码
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
SqlSession sqlSession = getSessionFactory().openSession();
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
JSONObject jsonObject = new JSONObject();
// jsonObject.put("page", "1"); // 当前页
// jsonObject.put("total", "1"); // 总页数
// 总记录数
jsonObject.put("current", 1);
jsonObject.put("rowCount", 10);
JSONArray rows = new JSONArray();
List<ResumeShow> si = userMapper.selectRShow();
int cont=si.size();
int cnt=1;
for (ResumeShow resumeShow : si) {
JSONObject cell = new JSONObject();
cell.put("id", cnt++);
cell.put("seeker_name", resumeShow.getSeeker_name());
cell.put("sex", resumeShow.getSex());
cell.put("age", resumeShow.getAge());
cell.put("residence", resumeShow.getResidence());
cell.put("education", resumeShow.getEducation());
cell.put("profession", resumeShow.getProfession());
cell.put("school", resumeShow.getSchool());
cell.put("expect_salary", resumeShow.getExpect_salary());
cell.put("work_place", resumeShow.getWork_place());
cell.put("last_company", resumeShow.getLast_company());
cell.put("position_name", resumeShow.getPosition_name());
cell.put("last_period", resumeShow.getLast_period());
cell.put("workYears", resumeShow.getWorkYears());
cell.put("household_registration", resumeShow.getHousehold_registration());
cell.put("job_category", resumeShow.getJob_category());
rows.add(cell);
}
jsonObject.put("rows", rows);
jsonObject.put("total", cont);
out.print(jsonObject);
}
private static SqlSessionFactory getSessionFactory() {
SqlSessionFactory sessionFactory = null;
String resource = "configuration.xml";
try {
sessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(resource));
} catch (IOException e) {
e.printStackTrace();
}
return sessionFactory;
}
public void init() throws ServletException {
// Put your code here
}
}
还有我的HTML
<table id="grid-command-buttons"
class="table table-bordered table-condensed table-hover table-striped tb" align="center">
<thead>
<tr class="gradient">
<th data-column-id="id">ID</th>
<th data-column-id="seeker_name">姓名</th>
<th data-column-id="sex">性别</th>
<th data-column-id="age">年龄</th>
<th data-column-id="residence">居住地</th>
<th data-column-id="education">学历</th>
<th data-column-id="profession">专业</th>
<th data-column-id="school">学校</th>
<th data-column-id="expect_salary">期望薪水</th>
<th data-column-id="work_place">工作地点</th>
<th data-column-id="last_company">公司</th>
<th data-column-id="position_name">职位名称</th>
<th data-column-id="last_period">时间</th>
<th data-column-id="workYears">总工作年限</th>
<th data-column-id="household_registration">户口</th>
<th data-column-id="job_category">期望工作职能</th>
</tr>
</thead>
</table>
当我取消用json数据,直接在HTML上添加表格数据的时候分页功能却可以工作了,这是为什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论