spring分页
1.Brand 商品品牌类
public class Brand {
private Integer id;
private String name;
private String description;
private String imgUrl;
private String webSite;
private Integer sort;
private Integer isDisplay;
private Integer pageNo=1; //页号
private Integer startRow; //开始行
private Integer pageSize = 10; //每页数
public String getAllUrl(){
return Constants.IMAGE_URL + imgUrl;
}
public Integer getstartRow() {
return startRow;
}
public void setstartRow(Integer startRow) {
this.startRow = startRow;
}
public Integer getPageSize() {
return pageSize;
}
public void setPageSize(Integer pageSize) {
this.startRow = (pageNo-1)* pageSize; //计算一次开始行
this.pageSize = pageSize;
}
public Integer getPageNo() {
return pageNo;
}
public void setPageNo(Integer pageNo) {
this.startRow = (pageNo-1)* pageSize; //计算一次开始行
this.pageNo = pageNo;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public String getWebSite() {
return webSite;
}
public void setWebSite(String webSite) {
this.webSite = webSite;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Integer getIsDisplay() {
return isDisplay;
}
public void setIsDisplay(Integer isDisplay) {
this.isDisplay = isDisplay;
}
@Override
public String toString() {
return "Brand [id=" + id + ", name=" + name + ", description=" + description + ", imgUrl=" + imgUrl
+ ", webSite=" + webSite + ", sort=" + sort + ", isDisplay=" + isDisplay + "]";
}
}
2.dao层
public interface BrandDao {
public List<Brand> getBrandListWithPage(Brand brand); //得到满足条件的所有品牌条目
public int getBrandCount();//获取总记录数
}
3.service层
public interface BrandService {
public Pagination getBrandListWithPage(Brand brand);
public void addBrand(Brand brand);
}
@Service
@Transactional
public class BrandServiceImpl implements BrandService{
@Resource
private BrandDao brandDao;
@Transactional(readOnly = true)
public Pagination getBrandListWithPage(Brand brand){
// 1.起始页 2.每页记录数 3.总记录数
Pagination pagination = new Pagination(brand.getPageNo(),brand.getPageSize(),brandDao.getBrandCount());
pagination.setList(brandDao.getBrandListWithPage(brand));
return pagination;
}
}
4.controller层
@Controller
public class BrandController {
@Autowired
private BrandService brandService;
@RequestMapping(value ="/brand/list.do")
public String list(String name, Integer isDisplay, Integer pageNo ,ModelMap model){
StringBuilder params = new StringBuilder();
Brand brand = new Brand();
if(StringUtils.isNotBlank(name)){ //="" 和" "都为空
brand.setName(name);
params.append("name=").append(name);
}
if(isDisplay!=null){
params.append("&").append("isDisplay=").append(isDisplay);
brand.setIsDisplay(isDisplay);
}else{
params.append("&").append("isDisplay=").append(1);
brand.setIsDisplay(1);
}
brand.setPageSize(5);
//如果页号是null或小于1 则重置为1
brand.setPageNo(Pagination.cpn(pageNo));
Pagination pagination = brandService.getBrandListWithPage(brand);
//分页展示: /brand/list.do?name=瑜伽树&isDisplay=1&pageNo=2
String url = "/brand/list.do";
pagination.pageView(url, params.toString());
model.addAttribute("pagination",pagination); //本质还是request.setAttribute();
model.addAttribute("name",name);
model.addAttribute("isDisplay",isDisplay);
return "brand/list";
//参数
}
}
5.jsp页面
<table cellspacing="1" cellpadding="0" border="0" width="100%" class="pn-ltable">
<thead class="pn-lthead">
<tr>
<th width="20"><input type="checkbox" onclick="checkBox('ids',this.checked)"/></th>
<th>品牌ID</th>
<th>品牌名称</th>
<th>品牌图片</th>
<th>品牌描述</th>
<th>排序</th>
<th>是否可用</th>
<th>操作选项</th>
</tr>
</thead>
<tbody class="pn-ltbody">
<c:forEach items="${pagination.list }" var="entry">
<tr bgcolor="#ffffff" onmouseout="this.bgColor='#ffffff'" onmouseover="this.bgColor='#eeeeee'">
<td><input type="checkbox" value="${entry.id }" name="ids"/></td>
<td align="center">${entry.id }</td>
<td align="center">${entry.name }</td>
<td align="center"><img width="40" height="40" src="${entry.allUrl}"/></td>
<td align="center">${entry.description }</td>
<td align="center">${entry.sort }</td>
<td align="center"><c:if test="${entry.isDisplay == 1 }">是</c:if><c:if test="${entry.isDisplay == 0 }">不是</c:if></td>
<td align="center">
<a class="pn-opt" href="#">修改</a> | <a class="pn-opt" href="/brand/delete.do?id=${entry.id }&name=${name}&isDisplay=${isDisplay}">删除</a>
</td>
</tr>
</c:forEach> </tbody>
</table>
<div class="page pb15">
<span class="r inb_a page_b">
<c:forEach items="${pagination.pageView }" var="page">
${page }
</c:forEach>
</span>
</div>
6.xml文件
<select id="getBrandListWithPage" parameterType="Brand" resultMap="brand">
select id , name ,description,img_url,sort,is_display
from bbs_brand
<where>
<if test="isDisplay != null">
is_display = #{isDisplay}
</if>
<if test="name != null">
and name = #{name} <!-- 查询所有品牌时为空 -->
</if>
</where>
order by id desc
limit #{startRow},#{pageSize}
</select>
显示结果:

spring分页的更多相关文章
- Spring分页实现PageImpl<T>类
Spring框架中PageImpl<T>类的源码如下: /* * Copyright 2008-2013 the original author or authors. * * Lice ...
- SSM框架搭建过程
引入依赖的jar包(pom.xml) a. <!--Spring SpringMVC相关--> spring-webmvc b. <!--Spring事务--> sprin ...
- struts2+spring+hibernate 实现分页
在这里要感谢下这位博友发表的博文 http://www.blogjava.net/rongxh7/archive/2008/11/29/243456.html 通过对他代码的阅读,从而自己实现了网页分 ...
- [转]Spring JdbcTemplate 查询分页
原文:http://blog.csdn.net/xiaofanku/article/details/4280128 现在进行的项目由于数据库的遗留原因(设计的不堪入目)不能用hibernate.所以用 ...
- spring和mybatis集成,自动生成model、mapper,增加mybatis分页功能
软件简介 Spring是一个流行的控制反转(IoC)和面向切面(AOP)的容器框架,在java webapp开发中使用广泛.http://projects.spring.io/spring-frame ...
- Spring + Mybatis 使用 PageHelper 插件分页
原文:http://www.cnblogs.com/yucongblog/p/5330886.html 先增加maven依赖: <dependency> <groupId>co ...
- 整合Spring Data JPA与Spring MVC: 分页和排序
之前我们学习了如何使用Jpa访问关系型数据库.比较完整Spring MVC和JPA教程请见Spring Data JPA实战入门,Spring MVC实战入门. 通过Jpa大大简化了我们对数据库的开发 ...
- Mybatis分页和Spring的集成
写了一个Mybatis分页控件,在这记录一下使用方式. 在Maven中加入依赖: ? 1 2 3 4 5 6 7 8 9 <dependencies> ... <depe ...
- 集成Spring后HibernateTemplate实现分页
spring 整合 hibernate 时候用的 HibernateTemplate 不支持分页,因此需要自己包装一个类进行分页,具体实现如下...使用spring的hibernateTemplate ...
随机推荐
- Nop常用知识点
1.列表标题与内容均居中对齐,列中配置为: headerAttributes: { style: "text-align:center" }, attributes: { styl ...
- <转载> GIT 操作小结 http://www.cnblogs.com/-ding/p/6008096.html
参考: http://www.cnblogs.com/zyf-zhaoyafei/p/4486220.html 作者:万境绝尘 转载请注明出处:http://blog.csdn.net/shulian ...
- mysql 外键引发的删除失败
mysql> TRUNCATE TABLE role ; ERROR 1701 (42000): Cannot truncate a table referenced in a foreign ...
- eclipse gradle插件 org.gradle.tooling.GradleConnectionException: Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-3.4-bin.zip'.
eclipse安装gradle后出现如下异常: org.gradle.tooling.GradleConnectionException: Could not install Gradle distr ...
- Spring.net介绍及MVC中应用
Spring.net两大核心内容: IOC(控制反转) 传统的面相对象思维模式是对象A依赖对象B,对象B的实例化和调用都在对象A中发生,一旦对象B中发生变化,对象A也要随之变化,这样使得程序间行程了紧 ...
- Mysql中select的正确姿势
引言 大家在开发中,还有很多童鞋在写查询语句的时候,习惯写下面这种不规范sql select * from table 而不写成下面的这种规范方式 select col1,col2,...,coln ...
- 用递归方法计算斐波那契数列第n项的和
参考: https://blog.csdn.net/xuzhangze/article/details/78568702 波那契数列数列从第3项开始,每一项都等于前两项之和.即 第n项的值为 (n- ...
- linux 开关机指令
shutdown -h now 现在关机 shutdown -h 1 1分钟后电脑关机 su 切换 用户 halt 关机 reboot 重启 sync :保存
- Netty socket.io 启用Epoll 模式异常
Epoll 环境为Linux 内核2.6 以上版本 Windows下不能启动 1:判断Linux环境 public static boolean isOSLinux() { Properties p ...
- beyondCompare工具使用
1.下载beyondcompare (从官网下载) 2.载入.class文件比对 参见: beyond compare 对class文件反编译及比较 (https://blog.csdn.net/ ...