springmvc使用json数据传递到bootstrap分页数据
1、服务器将查出的数据,以json字符串的形式返回给浏览器

3、在pom.xml中加入jackson依赖包。 <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.8</version> </dependency>

5、访问http://localhost:8080/ssm-crud2/emps,查看json数据是否正确返回。

7、重新修改控制层返回数据的方法:package com.gwolf.crud.controller;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.ResponseBody;import com.github.pagehelper.PageHelper;import com.github.pagehelper.PageInfo;import com.gwolf.crud.bean.Employee;import com.gwolf.crud.bean.Msg;import com.gwolf.crud.service.EmployeeService;@Controllerpublic class EmployeeController { @Autowired EmployeeService employeeService; @RequestMapping("/emps") @ResponseBody public Msg getEmpsWithJson(@RequestParam(value="pn",defaultValue="1") Integer pn,Model model) { PageHelper.startPage(pn, 5); List<Employee> employees = this.employeeService.getAll(); //传入连续显示的页数 PageInfo<Employee> pageInfo = new PageInfo<Employee>(employees,5); return Msg.success().add("pageInf", pageInfo); }}
