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>

显示结果:

  

最新文章

  1. NOIP2013火柴排队[逆序对]
  2. ASP.NET在IIS7.5(IIS7)配置伪静态
  3. 简单的json传送数据
  4. codeforces 630KIndivisibility(容斥原理)
  5. devi into python 笔记(七)locals与globals 字典格式化字符串 字符集
  6. NLP相关资源
  7. MySQL 5.6 root密码丢失,使用mysqld --skip-grant-tables
  8. longlistselector 闪烁问题研究
  9. Python实战:爬虫的基础
  10. [C#]如何访问及调用类中私有成员及方法
  11. snmp模拟器snmpsid使用
  12. react+umi+dva+antd中dva的数据流图解
  13. Codeforces 822E Liar dp + SA (看题解)
  14. 使用paramiko远程登录并执行命令脚本
  15. target runtime apache v6.0 not defined解决
  16. bioerl 获取gi号
  17. Java 使用new Thread和线程池的区别
  18. C++ 构造函数_内存分区_对象初始化
  19. aspnetcore 认证相关类简要说明一
  20. iOS NSString相关问题

热门文章

  1. centos磁盘挂载|centos虚拟机硬盘不够怎么办?|centos虚拟机硬盘的扩展
  2. linux获取内存、cpu、负载、网口流量、磁盘信息
  3. python时间日期字符串各种
  4. 38.纯 CSS 创作阶梯文字特效
  5. 20.纯 CSS 为母亲节创作一颗像素画风格的爱心
  6. 《算法》第四章部分程序 part 5
  7. zookeeper超时:Unable to connect to zookeeper server within timeout: 5000
  8. JavaScript 函数与对象的 简单区别
  9. Archlinux下vmware-workstation中安装rhel5并通过桥接模式(bridge)上网
  10. Android将Log写入文件