@WebServlet("/route/*") | |
public class RouteServlet extends BaseServlet { | |
private RouteService service = new RouteServiceImpl(); | |
/** | |
* 分页查询 | |
* @param request | |
* @param response | |
* @throws ServletException | |
* @throws IOException | |
*/ | |
public void pageQuery(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
// 1. 接收参数 | |
String currentPagestr = request.getParameter("currentPage"); | |
String pageSizestr = request.getParameter("pageSize"); | |
String cidstr = request.getParameter("cid"); | |
int cid = 0;// 类别 id | |
// 2. 处理参数 | |
if(cidstr != null && cidstr.length() > 0){ | |
cid = Integer.parseInt(cidstr); | |
} | |
int pageSize = 0; | |
if(pageSizestr != null && pageSizestr.length() >= 0){ | |
pageSize = Integer.parseInt(pageSizestr); | |
}else{ | |
pageSize = 5;// 每页显示条数,如果不传递默认显示 5 条 | |
} | |
int currentPage = 0; | |
if(currentPagestr != null && currentPagestr.length() >= 0){ | |
currentPage = Integer.parseInt(currentPagestr); | |
}else{ | |
currentPage = 1;// 当前页码,如果不传递默认显示为 1 | |
} | |
// 3. 调用 service 查询 PageBean 对象 | |
PageBean<Route> pd = service.pageQuery(cid,currentPage,pageSize); | |
// 4. 将 pageBean 对象序列化为 json 返回 | |
writeValue(pd,response); | |
} | |
} |
获取字段 getParameter ("xxx"), 获取后判断条件并转换为 int 类型