DepartmentController:
package com.wzy.controller;import com.github.pagehelper.PageInfo;import com.wzy.pojo.Department;import com.wzy.pojo.Msg;import com.wzy.service.DepartmentService;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controllerpublic class DepartmentController {private DepartmentService departmentService;@ResponseBody//使用jackson依赖后,可以将返回值,自动转为json@RequestMapping(value = "/departement")public Msg getDepart(){List<Department> departments = departmentService.getDepartment();/*** 使用pageInfo 包装查询到的信息,只需要将 使用pageInfo 交给 跳转输出页面* 封装了详细的分页信息。包括我们查询出来的数据* 第一个参数是封装查询到的结果,第二个参数是要连续显示的页数*/PageInfo pageInfo = new PageInfo(departments);//返回 pageInfo 的jsonreturn Msg.success().add("pageInfo",pageInfo);}}
DepartmentService:
package com.wzy.service;import com.wzy.dao.DepartmentMapper;import com.wzy.pojo.Department;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic class DepartmentService {@AutowiredDepartmentMapper departmentMapper;public List<Department> getDepartment(){//按条件查询,参数为 null 查询所有。List<Department> departments = departmentMapper.selectByExample(null);return departments;}}
