前端请求:
app.service("crudService",function($http){
//搜索
this.search=function(page,rows){
return $http.get('../findPage.do?page='+page+"&rows="+rows );
} })
// $scope.searchEntity={};//定义搜索对象
//搜索
$scope.search=function(page,rows){
crudService.search(page,rows).success(
function(response){
$scope.list=response.rows;
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
控制层:
/**
* 分页查询数据
* @param size
* @param rows
* @return
*/
@RequestMapping("/findPage")
public Map findPage(int page,int rows ){
PageResult pages = employeeService.findPage(page, rows);
System.out.println(pages.getTotal());
System.out.println(pages.getRows());
//获取员工数据
List<Employee> list = pages.getRows();
for (Employee employee : list) {
System.out.println("ID:"+employee.getEmpId()+"==>Name:"+employee.getEmpName());
}
Map map = new HashMap();
map.put("rows", pages.getTotal());
map.put("total", pages.getRows());
return map;
}前端发起请求的时候,后台能查询到数据,看到SQL打印的了:
JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@4aeed0e6] will be managed by Spring
==> Preparing: SELECT count(0) FROM emp
==> Parameters:
<== Columns: count(0)
<== Row: 1002
<== Total: 1
==> Preparing: select emp_id, emp_name, gender, email, d_id from emp LIMIT 10
==> Parameters:
<== Columns: emp_id, emp_name, gender, email, d_id
<== Row: 2, Jerry, M, [email protected], 1
<== Row: 3, Jerry, M, [email protected], 1
<== Row: 4, 89e290, M, [email protected], 1
<== Row: 5, 02e351, M, [email protected], 1
<== Row: 6, 52d4d2, M, [email protected], 1
<== Row: 7, c8e103, M, [email protected], 1
<== Row: 8, 453494, M, [email protected], 1
<== Row: 9, 6250c5, M, [email protected], 1
<== Row: 10, bc48d6, M, [email protected], 1
<== Row: 11, 996737, M, [email protected], 1
<== Total: 10
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
1002
Page{count=true, pageNum=1, pageSize=10, startRow=0, endRow=10, total=1002, pages=101, reasonable=true, pageSizeZero=false}
ID:2==>Name:Jerry
ID:3==>Name:Jerry
ID:4==>Name:89e290
ID:5==>Name:02e351
ID:6==>Name:52d4d2
ID:7==>Name:c8e103
ID:8==>Name:453494
ID:9==>Name:6250c5
ID:10==>Name:bc48d6
ID:11==>Name:996737
但是我前端的response怎么一直拿不到值,,还请各位大佬帮忙
// $scope.searchEntity={};//定义搜索对象
//搜索
$scope.search=function(page,rows){
crudService.search(page,rows).success(
function(response){
$scope.list=response.rows;
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
app.service("crudService",function($http){
//搜索
this.search=function(page,rows){
return $http.get('../findPage.do?page='+page+"&rows="+rows );
} })
// $scope.searchEntity={};//定义搜索对象
//搜索
$scope.search=function(page,rows){
crudService.search(page,rows).success(
function(response){
$scope.list=response.rows;
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
控制层:
/**
* 分页查询数据
* @param size
* @param rows
* @return
*/
@RequestMapping("/findPage")
public Map findPage(int page,int rows ){
PageResult pages = employeeService.findPage(page, rows);
System.out.println(pages.getTotal());
System.out.println(pages.getRows());
//获取员工数据
List<Employee> list = pages.getRows();
for (Employee employee : list) {
System.out.println("ID:"+employee.getEmpId()+"==>Name:"+employee.getEmpName());
}
Map map = new HashMap();
map.put("rows", pages.getTotal());
map.put("total", pages.getRows());
return map;
}前端发起请求的时候,后台能查询到数据,看到SQL打印的了:
JDBC Connection [com.mchange.v2.c3p0.impl.NewProxyConnection@4aeed0e6] will be managed by Spring
==> Preparing: SELECT count(0) FROM emp
==> Parameters:
<== Columns: count(0)
<== Row: 1002
<== Total: 1
==> Preparing: select emp_id, emp_name, gender, email, d_id from emp LIMIT 10
==> Parameters:
<== Columns: emp_id, emp_name, gender, email, d_id
<== Row: 2, Jerry, M, [email protected], 1
<== Row: 3, Jerry, M, [email protected], 1
<== Row: 4, 89e290, M, [email protected], 1
<== Row: 5, 02e351, M, [email protected], 1
<== Row: 6, 52d4d2, M, [email protected], 1
<== Row: 7, c8e103, M, [email protected], 1
<== Row: 8, 453494, M, [email protected], 1
<== Row: 9, 6250c5, M, [email protected], 1
<== Row: 10, bc48d6, M, [email protected], 1
<== Row: 11, 996737, M, [email protected], 1
<== Total: 10
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4b790a38]
1002
Page{count=true, pageNum=1, pageSize=10, startRow=0, endRow=10, total=1002, pages=101, reasonable=true, pageSizeZero=false}
ID:2==>Name:Jerry
ID:3==>Name:Jerry
ID:4==>Name:89e290
ID:5==>Name:02e351
ID:6==>Name:52d4d2
ID:7==>Name:c8e103
ID:8==>Name:453494
ID:9==>Name:6250c5
ID:10==>Name:bc48d6
ID:11==>Name:996737
但是我前端的response怎么一直拿不到值,,还请各位大佬帮忙
// $scope.searchEntity={};//定义搜索对象
//搜索
$scope.search=function(page,rows){
crudService.search(page,rows).success(
function(response){
$scope.list=response.rows;
$scope.paginationConf.totalItems=response.total;//更新总记录数
}
);
}
再把方法返回类型改成String,
方法最后将map通过json工具转换成json这样试试。
如果整个controller都是返回json而不是跳转页面那就加在类上。也可以用@RestController