springmvc restful风格的分页问题

「已注销」 2016-10-07 04:24:09
如题,我要把page当做参数,怎么传到url中?url的匹配使用的restful风格的url。
controller中的代码
@RequestMapping(name="/list",method = RequestMethod.GET)
public String list(Integer page, Model model){
page=1;
int rowsPerPage=4;
int start=(page-1)*rowsPerPage+1;
int end=start+rowsPerPage;
int pageSize=0;
int totalRows=secKillService.getSecKillListTotal();
if(totalRows%rowsPerPage==0){
pageSize=totalRows/rowsPerPage;
}else{
pageSize=(totalRows/rowsPerPage)+1;
}
model.addAttribute("page",page);
model.addAttribute("totalPages",pageSize);

List<Seckill> list=secKillService.getSecKillList(page-1,rowsPerPage);
model.addAttribute("list",list);
return "list";
}
页面中的分页代码已经写好,怎么使page传入进去呢??
页面部分的分页代码:
<div id="pages">
<a href="">首页</a>
<c:choose>
<c:when test="${page>1}">
<a href="/seckill/${page-1}">上一页</a>
</c:when>
<c:otherwise><a href="#">上一页</a></c:otherwise>
</c:choose>
<c:forEach begin="1" end="${totalPages}" var="p">
<c:choose>
<c:when test="${page==p}">
<a href="/list/${page}" class="current-page">${p}</a>
</c:when>
<c:otherwise>
<a href="/list/${page}" class="">${p}</a>
</c:otherwise>
</c:choose>
</c:forEach>
<c:choose>
<c:when test="${page<totalPages}">
<a href="/seckill/${page+1}">下一页</a>
</c:when>
<c:otherwise><a href="#">下一页</a></c:otherwise>
</c:choose>
<a href="/seckill/${totalPages}">末页</a>
</div>
...全文
597 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
有全的代码没,接口和service的
「已注销」 2016-10-08
  • 打赏
  • 举报
回复
引用 3 楼 abcdefghiijklmnopqrs 的回复:
/list/${page}要写成这样
前台页面访问的时候,进不到通过http://localhost:8080/seckill/,但是通过http://localhost:8080/seckill/list就访问不到,list后面接参数的时候,报404错误。。。。这个是为什么呢?web.xml中的配置: <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true"> <!--配置dispatchservlet--> <servlet> <servlet-name>seckill-dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--spring mvc需要加载的配置文件--> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-*.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>seckill-dispatcher</servlet-name> <!--默认匹配所有请求--> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
  • 打赏
  • 举报
回复
/list/${page}要写成这样
「已注销」 2016-10-08
  • 打赏
  • 举报
回复
引用 1 楼 abcdefghiijklmnopqrs 的回复:
@RequestMapping(name="/list/{page}",method = RequestMethod.GET)
    public String list(@PathVariable("page") Integer page, Model model){
        page=1;
        int rowsPerPage=4;
        int start=(page-1)*rowsPerPage+1;
        int end=start+rowsPerPage;
        int pageSize=0;
        int totalRows=secKillService.getSecKillListTotal();
        if(totalRows%rowsPerPage==0){
            pageSize=totalRows/rowsPerPage;
        }else{
            pageSize=(totalRows/rowsPerPage)+1;
        }
        model.addAttribute("page",page);
        model.addAttribute("totalPages",pageSize);

        List<Seckill> list=secKillService.getSecKillList(page-1,rowsPerPage);
        model.addAttribute("list",list);
        return "list";
    }
那我的页面上请求的时候,写成/list/{page}这样写对吗??
「已注销」 2016-10-08
  • 打赏
  • 举报
回复
引用 3 楼 abcdefghiijklmnopqrs 的回复:
/list/${page}要写成这样
我已经知道怎么写了,谢谢!
  • 打赏
  • 举报
回复
@RequestMapping(name="/list/{page}",method = RequestMethod.GET)
    public String list(@PathVariable("page") Integer page, Model model){
        page=1;
        int rowsPerPage=4;
        int start=(page-1)*rowsPerPage+1;
        int end=start+rowsPerPage;
        int pageSize=0;
        int totalRows=secKillService.getSecKillListTotal();
        if(totalRows%rowsPerPage==0){
            pageSize=totalRows/rowsPerPage;
        }else{
            pageSize=(totalRows/rowsPerPage)+1;
        }
        model.addAttribute("page",page);
        model.addAttribute("totalPages",pageSize);

        List<Seckill> list=secKillService.getSecKillList(page-1,rowsPerPage);
        model.addAttribute("list",list);
        return "list";
    }
内容概要:本文围绕SpringMVC RESTful API开发实战项目在毕业设计中的全流程应用展开,系统阐述了从需求分析、API设计、数据库建模到安全认证与业务逻辑实现的完整开发链条。重点介绍了JWT认证、权限控制、事务管理、时间冲突校验等企业级开发核心技术,并通过《智能教室预约系统》案例展示了SpringMVC与Spring Boot协同开发、RESTful API设计规范及Spring Security集成的实践方法。文章还展望了AI辅助开发与低代码平台融合的未来趋势,强调培养学生解决复杂工程问题的能力。; 适合人群:具备Java EE、Spring框架基础,正在进行或准备开展毕业设计的计算机相关专业本科生或研究生,尤其适合希望深入理解企业级API开发流程的学习者。; 使用场景及目标:①掌握基于SpringMVC和Spring Boot构建安全、可扩展的RESTful API的方法;②理解JWT认证机制、权限控制、事务处理等核心企业开发技术的实际应用;③将理论知识应用于毕业设计项目,提升工程实践能力与系统设计水平。; 阅读建议:建议结合文中提供的代码实例搭建开发环境进行实践,重点关注JWT认证流程、权限注解使用与业务异常处理机制,同时尝试扩展功能(如增加分页、过滤、日志审计)以深化理解。

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧