为什么创建不了pager对象呢
Pager.java
package com.imooc.shop.utils;
public class pager {
//当前页码
private int pageIndex = 1;
//每页展示的数据条数
private int pageSize = 3;
//当前条件下总的数据量
private int totalCount;
//一共多少页
private int totalPages;
public int getPageIndex() {
return pageIndex;
}
public void setPageIndex(int pageIndex) {
pageIndex = pageIndex<=0?1:pageIndex;
pageIndex = pageIndex>=getTotalPages()?getTotalPages():pageIndex;
this.pageIndex = pageIndex;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = (this.getTotalCount()-1)/this.getPageSize()+1;
}
}
ListServlet.java
package com.imooc.shop.action;
import com.imooc.shop.entity.Article;
import com.imooc.shop.entity.ArticleType;
import com.imooc.shop.service.ShopService;
import org.springframework.util.StringUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import static com.sun.deploy.config.JREInfo.getAll;
@WebServlet("/list")
public class ListServlet extends HttpServlet {
// 定义业务层对象
private HttpServletRequest request;
private HttpServletResponse response;
private ShopService shopService;
@Override
public void init() throws ServletException {
super.init();
// 获取sping的容器。然后从容器中得到业务层对象
ServletContext servletContext = this.getServletContext() ;
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
shopService = (ShopService) context.getBean("shopService");
}
@Override
protected void service(HttpServletRequest req,HttpServletResponse resp) throws ServletException, IOException,NullPointerException {
try {
this.request = req;
this.response = resp;
request.setCharacterEncoding("UTF-8");
String method = request.getParameter("method");
switch (method) {
case "getAll":
getAll();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void getAll () throws ServletException, IOException {
Pager pager = new Pager();
String typeCode = request.getParameter("typeCode");
String secondType = request.getParameter("secondType");
request.setAttribute("secondType",secondType);
String title = request.getParameter("title");
if(!StringUtils.isEmpty(typeCode)){
List<ArticleType> secondTypes = shopService.loadSecondArticleType(typeCode);
request.setAttribute("typeCode",typeCode);
request.setAttribute("secondTypes",secondTypes);
request.setAttribute("title",title);
}
List<ArticleType> firstArticleTypes = shopService.loadFirstArticleType();
List<Article> articles = shopService.getAllArticles(typeCode,secondType,title);
request.setAttribute("firstArticleTypes",firstArticleTypes);
request.setAttribute("articles",articles);
request.getRequestDispatcher("/WEB-INF/jsp/list.jsp").forward(request,response);
}
}

没有导包的提示,手动导包也没用
0
收起
正在回答
1回答
同学的包名创建的是pager,但是使用时误写为了Pager。同学统一一样就可以了

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
相似问题
登录后可查看更多问答,登录/注册
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星